Skip to content

#606. Initial framework for hardware SPI for ESP8266. #692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 10, 2015
Merged

#606. Initial framework for hardware SPI for ESP8266. #692

merged 9 commits into from
Nov 10, 2015

Conversation

nkolban
Copy link
Contributor

@nkolban nkolban commented Nov 4, 2015

The ESP8266 jshardware source file needs prepared for more detailed implementation of SPI hardware support. This commit includes the framework for implementation of those detailed functions.

The hardware SPI source files are also introduced in this commit with the corresponding Makefile change to include them in ESP8266 compilation.

@@ -1493,7 +1493,8 @@ LDFLAGS += -L$(ESP8266_SDK_ROOT)/lib \

# Extra source files specific to the ESP8266
SOURCES += targets/esp8266/uart.c \
targets/esp8266/user_main.c \
targets/esp8266/spi.c \
targets/esp8266/user_main.c \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like a space/tab mismatch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup ... sorry about that. Have corrected now.

The jshSPISend16 was not previously implemented and jshSPISend() did not
correctly honor input data of <0 value or return value properly.
@nkolban
Copy link
Contributor Author

nkolban commented Nov 10, 2015

Howdy ... is there something that needs attention with this Pull Request before it can be merged? Want to make sure that it isn't waiting on something I need to attend to.

@gfwilliams
Copy link
Member

Hi, sorry for the delay... Looks good - please could you just:

  • tweak the indenting in the Makefile to match?
  • add spi:1 to ESP8266_12.py - I don't see any reason not to at the moment? Anything we can do to keep them in sync for now is good.
  • Swap the licence text in targets/esp8266/spi.h/c to MPLv2? You said MetalPhreak was fine with that?

@nkolban
Copy link
Contributor Author

nkolban commented Nov 10, 2015

Requested changes made and committed.

@gfwilliams
Copy link
Member

Thanks, I'll merge - but you know you committed quite a lot of extra stuff this time as well? Or was adding NeoPixel intentional?

https://github.com/nkolban/Espruino/commit/71d19752eea5941db68f8945d23969ba04da64c7

The AES branch is now merged too, so you could massively simplify your NeoPixel code.Literally just the following will do:

/*JSON{
 "type"     : "staticmethod",
 "class"    : "ESP8266",
 "name"     : "neopixelWrite",
 "generate" : "jswrap_ESP8266_neopixelWrite",
 "params"   : [
   ["pin", "pin", "Pin for output signal."],
   ["arrayOfData", "JsVar", "Array of LED data."]
 ]
}*/
void jswrap_ESP8266_neopixelWrite(Pin pin, JsVar *jsArrayOfData) {
  if (!jshIsPinValid(pin)) {
    jsExceptionHere(JSET_ERROR, "Pin is not valid.");
    return;
  }
  JSV_GET_AS_CHAR_ARRAY(dataPtr, dataLen, jsArrayOfData);
  if (!dataPtr) return 0;
 // ...

Note also that you can set the variable type in the JSON to pin and the conversion is done for you. Same for ints and floats too.

gfwilliams added a commit that referenced this pull request Nov 10, 2015
#606. Initial framework for hardware SPI for ESP8266.
@gfwilliams gfwilliams merged commit 471b8e1 into espruino:master Nov 10, 2015
@nkolban
Copy link
Contributor Author

nkolban commented Nov 10, 2015

Pure gold!!! I had no idea that the params section of JSON was more than documentation ... and had been filling it in as a good citizen by accident. I didn't know it could dynamically cast parameters ... VERY nice.

The JSV_GET_AS_CHAR_ARRAY is also nice however I had to convince myself that I could understand it. It seems to create new variables which I found an unusual side effect for a macro. I can't say it is wrong ... just unusual (to me).

I have accommodated both changes and after testing, will commit them with the next batch.

@gfwilliams
Copy link
Member

Thanks!

Yes, I was unsure about that behaviour, but the variables always have to be the same time so it seemed to make sense to avoid duplication. Maybe not...

For the JSON, it's used for the reference, to define how the function gets called, and for autocomplete in the Web IDE.

Some info here, maybe it needs clearing up a bit though:

... by making all the type conversions automatic, Espruino cuts out on all the duplicated code that handles that so it doesn't use up much Flash. It's also removing another potential source of bugs :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants