/* * This file is part of Espruino, a JavaScript interpreter for Microcontrollers * * Copyright (C) 2015 Gordon Williams * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * ---------------------------------------------------------------------------- * This file is designed to be parsed during the build process * * Contains ESP8266 board specific functions. * ---------------------------------------------------------------------------- */ /* DO_NOT_INCLUDE_IN_DOCS - this is a special token for common.py, so we don't put this into espruino.com/Reference until this is out of beta. */ // Because the ESP8266 JS wrapper is assured to be running on an ESP8266 we // can assume that inclusion of ESP8266 headers will be acceptable. #include #include #include #include #include #include #include #include #define _GCC_WRAP_STDINT_H typedef long long int64_t; #include #include "jsinteractive.h" // Pull inn the jsiConsolePrint function #define _BV(bit) (1 << (bit)) static uint32_t _getCycleCount(void) __attribute__((always_inline)); static inline uint32_t _getCycleCount(void) { uint32_t ccount; __asm__ __volatile__("rsr %0,ccount":"=a" (ccount)); return ccount; } /*JSON{ "type" : "staticmethod", "class" : "ESP8266", "name" : "neopixelWrite", "generate" : "jswrap_ESP8266_neopixelWrite", "params" : [ ["pin", "pin", "Pin for output signal."], ["arrayOfData", "JsVar", "Array of LED data."] ] }*/ __attribute__((section(".force.text"))) void jswrap_ESP8266_neopixelWrite(Pin pin, JsVar *jsArrayOfData) { if (!jshIsPinValid(pin)) { jsExceptionHere(JSET_ERROR, "Pin is not valid."); return; } if (jsArrayOfData == NULL) { jsExceptionHere(JSET_ERROR, "No data to send to LEDs."); return; } if (!jsvIsArray(jsArrayOfData)) { jsExceptionHere(JSET_ERROR, "Data must be an array."); return; } JSV_GET_AS_CHAR_ARRAY(pixels, dataLength, jsArrayOfData); if (!pixels) { return; } if (dataLength == 0) { jsExceptionHere(JSET_ERROR, "Data must be a non empty array."); return; } if (dataLength % 3 != 0) { jsExceptionHere(JSET_ERROR, "Data length must multiples of RGB bytes (3)."); return; } for (size_t i=0; i>= 1)) { // Next bit/byte if (p >= end) break; pix = *p++; mask = 0x80; } while (((c = _getCycleCount()) - startTime) < period) ; // Wait for bit start } while ((_getCycleCount() - startTime) < period) ; // Wait for last bit }