Skip to content

Commit 908ed13

Browse files
committed
Code changes for SPI testing.
See #588
1 parent 07aac1c commit 908ed13

16 files changed

+840
-412
lines changed

boards/ESP8266_BOARD.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@
4343
""";
4444

4545
def get_pins():
46-
pins = pinutils.generate_pins(0,7)
47-
# just fake pins D0 .. D7
48-
return pins
46+
pins = pinutils.generate_pins(0,15)
47+
# just fake pins D0 .. D15
48+
return pins

doxygen/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/html/
2+
/latex/

libs/network/esp8266/jswrap_esp8266.c

+31-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Because the ESP8266 JS wrapper is assured to be running on an ESP8266 we
2+
// can assume that inclusion of ESP8266 headers will be acceptable.
13
#include <c_types.h>
24
#include <user_interface.h>
35
#include <mem.h>
@@ -60,7 +62,13 @@ static struct ping_option pingOpt;
6062
["gotIpCallback", "JsVar", "An optional callback invoked when we have an IP"]
6163
]
6264
}*/
63-
void jswrap_ESP8266WiFi_connect(JsVar *jsv_ssid, JsVar *jsv_password, JsVar *gotIpCallback) {
65+
void jswrap_ESP8266WiFi_connect(
66+
JsVar *jsv_ssid, //!< The SSID of the access point to connect.
67+
JsVar *jsv_password, //!< The password for the access point.
68+
JsVar *gotIpCallback //!< The Callback function to be called when we are connected.
69+
) {
70+
os_printf("> jswrap_ESP8266WiFi_connect\n");
71+
6472
// Check that the ssid and password values aren't obviously in error.
6573
if (jsv_ssid == NULL || !jsvIsString(jsv_ssid)) {
6674
jsExceptionHere(JSET_ERROR, "No SSID.");
@@ -86,6 +94,8 @@ void jswrap_ESP8266WiFi_connect(JsVar *jsv_ssid, JsVar *jsv_password, JsVar *got
8694
jsvUnLock(jsGotIpCallback);
8795
jsGotIpCallback = NULL;
8896
}
97+
98+
// What does this do?
8999
if (gotIpCallback != NULL) {
90100
jsGotIpCallback = jsvLockAgainSafe(gotIpCallback);
91101
}
@@ -98,8 +108,7 @@ void jswrap_ESP8266WiFi_connect(JsVar *jsv_ssid, JsVar *jsv_password, JsVar *got
98108
len = jsvGetString(jsv_password, password, sizeof(password)-1);
99109
password[len]='\0';
100110

101-
jsiConsolePrintf("jswrap_ESP8266WiFi_connect: %s - %s\r\n", ssid, password);
102-
111+
os_printf("> - ssid=%s, password=%s\n", ssid, password);
103112
// Set the WiFi mode of the ESP8266
104113
wifi_set_opmode_current(STATION_MODE);
105114

@@ -115,10 +124,11 @@ void jswrap_ESP8266WiFi_connect(JsVar *jsv_ssid, JsVar *jsv_password, JsVar *got
115124
// Set the WiFi configuration
116125
wifi_station_set_config(&stationConfig);
117126

118-
// Register the event handler
127+
// Register the event handler for callbacks from ESP8266
119128
wifi_set_event_handler_cb(wifiEventHandler);
120129

121130
wifi_station_connect();
131+
os_printf("< jswrap_ESP8266WiFi_connect\n");
122132
} // End of jswrap_ESP8266WiFi_connect
123133

124134

@@ -209,24 +219,26 @@ void jswrap_ESP8266WiFi_beAccessPoint(
209219
void jswrap_ESP8266WiFi_getAccessPoints(
210220
JsVar *callback //!< Function to call back when access points retrieved.
211221
) {
212-
jsiConsolePrint("> ESP8266WiFi_getAccessPoints\n");
222+
os_printf("> ESP8266WiFi_getAccessPoints\n");
213223
if (callback == NULL || !jsvIsFunction(callback)) {
214224
jsExceptionHere(JSET_ERROR, "No callback.");
215225
return;
216226
}
217227

218-
// Save the callback for the scan
228+
// Save the callback for the scan in the global variable called jsScanCallback.
219229
jsScanCallback = jsvLockAgainSafe(callback);
220230

221231
// Ask the ESP8266 to perform a network scan after first entering
222-
// station mode. This will result in an eventual callback which is where
232+
// station mode. The network scan will eventually result in a callback
233+
// being executed (scanCB) which will contain the results.
234+
223235
// Ensure we are in station mode
224236
wifi_set_opmode_current(STATION_MODE);
225237

226238
// Request a scan of the network calling "scanCB" on completion
227239
wifi_station_scan(NULL, scanCB);
228240

229-
jsiConsolePrint("< ESP8266WiFi_getAccessPoints\n");
241+
os_printf("< ESP8266WiFi_getAccessPoints\n");
230242
} // End of jswrap_ESP8266WiFi_getAccessPoints
231243

232244

@@ -812,6 +824,7 @@ static void scanCB(void *arg, STATUS status) {
812824
* of records.
813825
*/
814826

827+
os_printf(">> scanCB\n");
815828
// Create the Empty JS array that will be passed as a parameter to the callback.
816829
JsVar *accessPointArray = jsvNewArray(NULL, 0);
817830
struct bss_info *bssInfo;
@@ -851,7 +864,7 @@ static void scanCB(void *arg, STATUS status) {
851864
// Add the new record to the array
852865
jsvArrayPush(accessPointArray, currentAccessPoint);
853866

854-
os_printf("ssid: %s\n", bssInfo->ssid);
867+
os_printf(" - ssid: %s\n", bssInfo->ssid);
855868
bssInfo = STAILQ_NEXT(bssInfo, next);
856869
} // End of loop over the records.
857870

@@ -860,6 +873,7 @@ static void scanCB(void *arg, STATUS status) {
860873
params[0] = accessPointArray;
861874
jsiQueueEvents(NULL, jsScanCallback, params, 1);
862875
jsvUnLock(jsScanCallback);
876+
os_printf("<< scanCB\n");
863877
} // End of scanCB
864878

865879

@@ -894,16 +908,19 @@ static void sendWifiEvent(uint32 eventType, JsVar *details) {
894908
/**
895909
* \brief ESP8266 WiFi Event handler.
896910
* This function is called by the ESP8266
897-
* environment when significant events happend related to the WiFi environment.
911+
* environment when significant events happen related to the WiFi environment.
898912
* The event handler is registered with a call to wifi_set_event_handler_cb()
899913
* that is provided by the ESP8266 SDK.
900914
*/
901915
static void wifiEventHandler(System_Event_t *event) {
902916
switch(event->event) {
917+
// We have connected to an access point.
903918
case EVENT_STAMODE_CONNECTED:
904919
os_printf("Event: EVENT_STAMODE_CONNECTED\n");
905920
sendWifiEvent(event->event, jsvNewNull());
906921
break;
922+
923+
// We have disconnected or been disconnected from an access point.
907924
case EVENT_STAMODE_DISCONNECTED:
908925
os_printf("Event: EVENT_STAMODE_DISCONNECTED\n");
909926
JsVar *details = jspNewObject(NULL, "EventDetails");
@@ -913,10 +930,14 @@ static void wifiEventHandler(System_Event_t *event) {
913930
ssid[ event->event_info.disconnected.ssid_len] = '\0';
914931
sendWifiEvent(event->event, details);
915932
break;
933+
934+
// The authentication information at the access point has changed.
916935
case EVENT_STAMODE_AUTHMODE_CHANGE:
917936
os_printf("Event: EVENT_STAMODE_AUTHMODE_CHANGE\n");
918937
sendWifiEvent(event->event, jsvNewNull());
919938
break;
939+
940+
// We have been allocated an IP address.
920941
case EVENT_STAMODE_GOT_IP:
921942
os_printf("Event: EVENT_STAMODE_GOT_IP\n");
922943
sendWifiEvent(event->event, jsvNewNull());

libs/network/esp8266/network_esp8266.c

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
*
2929
*/
3030
// ESP8266 specific includes
31+
#define ESPSDK_1_3_0
3132
#include <c_types.h>
3233
#include <user_interface.h>
3334
#include <mem.h>

src/jshardware.h

+26-15
Original file line numberDiff line numberDiff line change
@@ -183,24 +183,35 @@ typedef enum {
183183
SPIB_MINIMUM,// baudRate is the minimum we'll choose
184184
} PACKED_FLAGS JshBaudFlags;
185185

186+
/**
187+
* \brief Definition of an SPI interface.
188+
*/
186189
typedef struct {
187-
int baudRate;
188-
JshBaudFlags baudRateSpec;
189-
Pin pinSCK;
190-
Pin pinMISO;
191-
Pin pinMOSI;
192-
unsigned char spiMode;
193-
bool spiMSB; // MSB first?
190+
int baudRate; //!< Baud rate.
191+
JshBaudFlags baudRateSpec; //!<
192+
Pin pinSCK; //!< Pin to use for clock.
193+
Pin pinMISO; //!< Pin to use for Master In/Slave Out.
194+
Pin pinMOSI; //!< Pin to use for Master Out/Slave In.
195+
unsigned char spiMode; //!<
196+
bool spiMSB; //!< MSB first?
194197
} PACKED_FLAGS JshSPIInfo;
195-
static inline void jshSPIInitInfo(JshSPIInfo *inf) {
196-
inf->baudRate = 100000;
198+
199+
200+
/**
201+
* \brief Initialize a JshSPIInfo structure to defaults.
202+
*/
203+
static inline void jshSPIInitInfo(
204+
JshSPIInfo *inf //!< The JshSPIInfo structure to initialize to defaults.
205+
) {
206+
inf->baudRate = 100000;
197207
inf->baudRateSpec = SPIB_DEFAULT;
198-
inf->pinSCK = PIN_UNDEFINED;
199-
inf->pinMISO = PIN_UNDEFINED;
200-
inf->pinMOSI = PIN_UNDEFINED;
201-
inf->spiMode = SPIF_SPI_MODE_0;
202-
inf->spiMSB = true; // MSB first is default
203-
}
208+
inf->pinSCK = PIN_UNDEFINED;
209+
inf->pinMISO = PIN_UNDEFINED;
210+
inf->pinMOSI = PIN_UNDEFINED;
211+
inf->spiMode = SPIF_SPI_MODE_0;
212+
inf->spiMSB = true; // MSB first is default
213+
} // End of jshSPIInitInfo.
214+
204215

205216
/** Set up SPI, if pins are -1 they will be guessed */
206217
void jshSPISetup(IOEventFlags device, JshSPIInfo *inf);

src/jsinteractive.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ void jsiDebuggerLine(JsVar *line);
7070

7171
// ----------------------------------------------------------------------------
7272

73+
/**
74+
* \brief Get the device from the class variable.
75+
*/
7376
IOEventFlags jsiGetDeviceFromClass(JsVar *class) {
7477
// Devices have their Object data set up to something special
7578
// See jspNewObject
@@ -79,7 +82,8 @@ IOEventFlags jsiGetDeviceFromClass(JsVar *class) {
7982
return (IOEventFlags)class->varData.str[3];
8083

8184
return EV_NONE;
82-
}
85+
} // End of jsiGetDeviceFromClass
86+
8387

8488
JsVar *jsiGetClassNameFromDevice(IOEventFlags device) {
8589
const char *deviceName = jshGetDeviceString(device);
@@ -161,12 +165,16 @@ NO_INLINE void jsiConsolePrint(const char *str) {
161165
}
162166
}
163167

168+
/**
169+
* \brief Perform a printf to the console.
170+
* Execute a printf command to the current JS console.
171+
*/
164172
void jsiConsolePrintf(const char *fmt, ...) {
165173
va_list argp;
166174
va_start(argp, fmt);
167175
vcbprintf((vcbprintf_callback)jsiConsolePrint,0, fmt, argp);
168176
va_end(argp);
169-
}
177+
} // End of jsiConsolePrintf
170178

171179
/// Print the contents of a string var from a character position until end of line (adding an extra ' ' to delete a character if there was one)
172180
void jsiConsolePrintStringVarUntilEOL(JsVar *v, size_t fromCharacter, size_t maxChars, bool andBackup) {

0 commit comments

Comments
 (0)