Skip to content

Commit

Permalink
Allow Ili9341 variables at the module scope
Browse files Browse the repository at this point in the history
These statements no longer cause an error at the module scope:
let tft = initIli9321(9, 10)

Introduces a C++ subclass with a default constructor.
Workaround for nim-lang/Nim#14389
  • Loading branch information
markspanbroek committed Feb 26, 2021
1 parent a7f770d commit 06bffcc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
7 changes: 4 additions & 3 deletions ili9341.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import pkg/nim-adafruit-gfx/gfx

export gfx

{.push header:"<Adafruit_ILI9341.h>".}
{.push header: "workaround.h".}

type
Ili9341 {.importcpp: "Adafruit_ILI9341".} = object of Gfx
Ili9341* {.importcpp: "Adafruit_ILI9341_Workaround".} = object of Gfx

{.push importcpp: "Adafruit_ILI9341(@)", constructor.}
{.push importcpp: "Adafruit_ILI9341_Workaround(@)", constructor.}
proc initIli9321*(cs, dc: uint16): Ili9341
{.pop.}

Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nim-ili9341",
"version": "0.1.0",
"version": "0.1.1",
"license": "MIT",
"dependencies": {
"nim-adafruit-gfx": "https://github.com/markspanbroek/nim-adafruit-gfx",
Expand Down
10 changes: 10 additions & 0 deletions workaround.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <Adafruit_ILI9341.h>

// Adds a default constructor to Adafruit_ILI9341, to work around this issue:
// https://github.com/nim-lang/Nim/issues/14389

class Adafruit_ILI9341_Workaround : public Adafruit_ILI9341 {
public:
Adafruit_ILI9341_Workaround(int8_t _CS, int8_t _DC): Adafruit_ILI9341(_CS, _DC) {}
Adafruit_ILI9341_Workaround(): Adafruit_ILI9341(-1, -1) {}
};

0 comments on commit 06bffcc

Please sign in to comment.