Created
August 16, 2021 16:01
-
-
Save ihewitt/02eafbdca28569b7dfd965067b7c996e to your computer and use it in GitHub Desktop.
Initial bangle hack/patch for non gps F18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/boards/BANGLEJS.py b/boards/BANGLEJS.py | |
index 4f392c41..d0efe436 100644 | |
--- a/boards/BANGLEJS.py | |
+++ b/boards/BANGLEJS.py | |
@@ -29,8 +29,8 @@ info = { | |
'BLUETOOTH', | |
'TERMINAL', | |
'GRAPHICS', | |
- 'LCD_ST7789_8BIT', | |
- 'TENSORFLOW' | |
+ 'LCD_ST7789_8BIT'#, | |
+ #'TENSORFLOW' | |
], | |
'makefile' : [ | |
'DEFINES += -DESPR_HWVERSION=1', | |
@@ -92,13 +92,13 @@ devices = { | |
'BTN4' : { 'pin' : 'D11', 'pinstate' : 'IN_PULLDOWN' }, # touch left | |
'BTN5' : { 'pin' : 'D16', 'pinstate' : 'IN_PULLDOWN' }, # touch right | |
'VIBRATE' : { 'pin' : 'D13' }, | |
- 'SPEAKER' : { 'pin' : 'D18' }, | |
+# 'SPEAKER' : { 'pin' : 'D18' }, | |
'LCD' : { | |
'width' : 240, 'height' : 240, 'bpp' : 16, | |
'controller' : 'st7789_8bit', # 8 bit parallel mode | |
'pin_dc' : 'D8', | |
'pin_cs' : 'D10', | |
-# 'pin_rst' : '', # IO expander P6 | |
+ 'pin_rst' : 'D18', | |
'pin_sck' : 'D9', | |
'pin_d0' : 'D0', | |
'pin_d1' : 'D1', | |
@@ -108,48 +108,49 @@ devices = { | |
'pin_d5' : 'D5', | |
'pin_d6' : 'D6', | |
'pin_d7' : 'D7', | |
-# 'pin_bl' : '', # IO expander P5 | |
- }, | |
- 'GPS' : { | |
- 'device' : 'M8130-KT', | |
-# 'pin_en' : '', # IO expander P0 | |
- 'pin_rx' : 'D25', | |
- 'pin_tx' : 'D26' | |
+ 'pin_bl' : 'D14' | |
}, | |
+# 'GPS' : { | |
+# 'device' : 'M8130-KT', | |
+## 'pin_en' : '', # IO expander P0 | |
+# 'pin_rx' : 'D25', | |
+# 'pin_tx' : 'D26' | |
+# }, | |
'BAT' : { | |
'pin_charging' : 'D12', # active low, input pullup | |
'pin_voltage' : 'D30' | |
}, | |
'HEARTRATE' : { | |
'device' : 'analog', | |
- # 'pin_led' : '', IO expander P7 | |
+ 'pin_led' : 'D15', | |
'pin_analog' : 'D29' | |
}, | |
'ACCEL' : { | |
'device' : 'KX023', 'addr' : 0x1e, | |
- 'pin_sda' : 'D15', | |
- 'pin_scl' : 'D14' | |
+ 'pin_sda' : 'D19', #D15 | |
+ 'pin_scl' : 'D20' #D14 | |
}, | |
'MAG' : { # Magnetometer/compass | |
'device' : 'GMC303', | |
'addr' : 0x0C, | |
- 'pin_sda' : 'D15', | |
- 'pin_scl' : 'D14' | |
+ 'pin_sda' : 'D19', #D15 | |
+ 'pin_scl' : 'D20' #D14 | |
}, | |
'SPIFLASH' : { | |
- 'pin_cs' : 'D21', | |
- 'pin_sck' : 'D19', | |
+ 'pin_cs' : 'D25', | |
+ 'pin_sck' : 'D28', | |
'pin_mosi' : 'D27', # D0 | |
- 'pin_miso' : 'D20', # D1 | |
+ 'pin_miso' : 'D26', # D1 | |
'pin_wp' : 'D31', # D2 | |
- 'pin_rst' : 'D17', # D3 | |
+ 'pin_rst' : 'D21', # D3 | |
'size' : 4096*1024, # 4MB | |
'memmap_base' : 0x60000000 # map into the address space (in software) | |
- }, | |
- 'MISC' : { | |
- 'pin_nenable' : 'D18', # needed to get power to Bangle.js peripherals | |
- 'pin_ioexp_reset' : 'D28', | |
- } | |
+ } | |
+# }, | |
+# 'MISC' : { | |
+# 'pin_nenable' : 'D18', # needed to get power to Bangle.js peripherals | |
+# 'pin_ioexp_reset' : 'D28', | |
+# } | |
}; | |
# left-right, or top-bottom order | |
@@ -192,10 +193,10 @@ def get_pins(): | |
pinutils.findpin(pins, "PD3", True)["functions"]["ADC1_IN1"]=0; | |
pinutils.findpin(pins, "PD4", True)["functions"]["ADC1_IN2"]=0; | |
pinutils.findpin(pins, "PD5", True)["functions"]["ADC1_IN3"]=0; | |
- pinutils.findpin(pins, "PD28", True)["functions"]["ADC1_IN4"]=0; | |
+# pinutils.findpin(pins, "PD28", True)["functions"]["ADC1_IN4"]=0;## | |
pinutils.findpin(pins, "PD29", True)["functions"]["ADC1_IN5"]=0; | |
pinutils.findpin(pins, "PD30", True)["functions"]["ADC1_IN6"]=0; | |
- pinutils.findpin(pins, "PD31", True)["functions"]["ADC1_IN7"]=0; | |
+# pinutils.findpin(pins, "PD31", True)["functions"]["ADC1_IN7"]=0;## | |
# negate buttons | |
pinutils.findpin(pins, "PD11", True)["functions"]["NEGATED"]=0; # btn | |
pinutils.findpin(pins, "PD16", True)["functions"]["NEGATED"]=0; # btn | |
diff --git a/libs/banglejs/jswrap_bangle.c b/libs/banglejs/jswrap_bangle.c | |
index aa7fa254..439a53aa 100644 | |
--- a/libs/banglejs/jswrap_bangle.c | |
+++ b/libs/banglejs/jswrap_bangle.c | |
@@ -375,11 +375,11 @@ APP_TIMER_DEF(m_backlight_off_timer_id); | |
#define HOME_BTN 3 | |
#define BACKLIGHT_PWM_INTERVAL 15 // in msec - 67Hz PWM | |
#define HEARTRATE 1 | |
-#define GPS_UART EV_SERIAL1 | |
-#define IOEXP_GPS 0x01 | |
-#define IOEXP_LCD_BACKLIGHT 0x20 | |
-#define IOEXP_LCD_RESET 0x40 | |
-#define IOEXP_HRM 0x80 | |
+//#define GPS_UART EV_SERIAL1 | |
+//#define IOEXP_GPS 0x01 | |
+//#define IOEXP_LCD_BACKLIGHT 0x20 | |
+//#define IOEXP_LCD_RESET 0x40 | |
+//#define IOEXP_HRM 0x80 | |
#endif | |
#ifdef EMSCRIPTEN | |
@@ -682,16 +682,16 @@ JsBangleTasks bangleTasks; | |
static void jswrap_banglejs_setLCDPowerBacklight(bool isOn); | |
-void jswrap_banglejs_pwrGPS(bool on) { | |
- if (on) bangleFlags |= JSBF_GPS_ON; | |
- else bangleFlags &= ~JSBF_GPS_ON; | |
-#ifdef BANGLEJS_F18 | |
- jswrap_banglejs_ioWr(IOEXP_GPS, on); | |
-#endif | |
-#ifdef GPS_PIN_EN | |
- jshPinOutput(GPS_PIN_EN, on); | |
-#endif | |
-} | |
+// void jswrap_banglejs_pwrGPS(bool on) { | |
+// if (on) bangleFlags |= JSBF_GPS_ON; | |
+// else bangleFlags &= ~JSBF_GPS_ON; | |
+// #ifdef BANGLEJS_F18 | |
+// jswrap_banglejs_ioWr(IOEXP_GPS, on); | |
+// #endif | |
+// #ifdef GPS_PIN_EN | |
+// jshPinOutput(GPS_PIN_EN, on); | |
+// #endif | |
+// } | |
void jswrap_banglejs_pwrHRM(bool on) { | |
#ifdef HEARTRATE | |
@@ -699,19 +699,22 @@ void jswrap_banglejs_pwrHRM(bool on) { | |
else bangleFlags &= ~JSBF_HRM_ON; | |
#endif | |
#ifdef BANGLEJS_F18 | |
- jswrap_banglejs_ioWr(IOEXP_HRM, !on); | |
+// jswrap_banglejs_ioWr(IOEXP_HRM, !on); | |
+ jshPinOutput(HEARTRATE_PIN_LED, !on); | |
+ | |
#endif | |
#ifdef HEARTRATE_PIN_EN | |
- jshPinOutput(HEARTRATE_PIN_EN, on); | |
+// jshPinOutput(HEARTRATE_PIN_EN, on); | |
#endif | |
} | |
void jswrap_banglejs_pwrBacklight(bool on) { | |
#ifdef BANGLEJS_F18 | |
- jswrap_banglejs_ioWr(IOEXP_LCD_BACKLIGHT, !on); | |
+// jswrap_banglejs_ioWr(IOEXP_LCD_BACKLIGHT, !on); | |
+ jshPinOutput(LCD_PIN_BL, !on); | |
#endif | |
#ifdef LCD_BL | |
- jshPinOutput(LCD_BL, on); | |
+// jshPinOutput(LCD_BL, on); | |
#endif | |
#ifdef LCD_CONTROLLER_LPM013M126 | |
lcdMemLCD_extcominBacklight(on); | |
@@ -2140,8 +2143,12 @@ Get the last available GPS fix info (or `undefined` if GPS is off). | |
The fix info received is the same as you'd get from the `Bangle.GPS` event. | |
*/ | |
JsVar *jswrap_banglejs_getGPSFix() { | |
+#ifdef GPS_PIN_RX | |
if (!jswrap_banglejs_isGPSOn()) return NULL; | |
return nmea_to_jsVar(&gpsFix); | |
+#else | |
+ return NULL; | |
+#endif | |
} | |
/*JSON{ | |
@@ -2443,6 +2450,13 @@ void jswrap_banglejs_postInit() { | |
#endif | |
} | |
+void buzz() { | |
+jshPinOutput(VIBRATE_PIN,1); // vibrate off | |
+jshDelayMicroseconds(50000); | |
+jshPinOutput(VIBRATE_PIN,0); // vibrate off | |
+jshDelayMicroseconds(50000); | |
+} | |
+ | |
/*JSON{ | |
"type" : "init", | |
"generate" : "jswrap_banglejs_init" | |
@@ -2453,7 +2467,9 @@ NO_INLINE void jswrap_banglejs_init() { | |
// Hardware init that we only do the very first time we start | |
if (firstRun) { | |
#ifdef BANGLEJS_F18 | |
- jshPinOutput(18,0); // what's this? | |
+ | |
+// jshPinOutput(18,0); // what's this? | |
+ | |
#endif | |
#ifdef ID205 | |
jshPinOutput(3,1); // general VDD power? | |
@@ -2520,16 +2536,20 @@ NO_INLINE void jswrap_banglejs_init() { | |
jshPinOutput(LCD_PIN_SCK, 1); | |
for (int i=0;i<8;i++) jshPinOutput(i, 0); | |
// IO expander reset | |
- jshPinOutput(28,0); | |
- jshDelayMicroseconds(10000); | |
- jshPinOutput(28,1); | |
- jshDelayMicroseconds(50000); | |
- jswrap_banglejs_ioWr(0,0); | |
+// jshPinOutput(28,0); | |
+// jshDelayMicroseconds(10000); | |
+// jshPinOutput(28,1); | |
+// jshDelayMicroseconds(50000); | |
+// jswrap_banglejs_ioWr(0,0); | |
jswrap_banglejs_pwrHRM(false); // HRM off | |
+#ifdef GPS_PIN_RX | |
jswrap_banglejs_pwrGPS(false); // GPS off | |
- jswrap_banglejs_ioWr(IOEXP_LCD_RESET,0); // LCD reset on | |
+#endif | |
+// jswrap_banglejs_ioWr(IOEXP_LCD_RESET,0); // LCD reset on | |
+ jshPinOutput(LCD_PIN_RST, 0); | |
jshDelayMicroseconds(100000); | |
- jswrap_banglejs_ioWr(IOEXP_LCD_RESET,1); // LCD reset off | |
+// jswrap_banglejs_ioWr(IOEXP_LCD_RESET,1); // LCD reset off | |
+ jshPinOutput(LCD_PIN_RST, 1); | |
jswrap_banglejs_pwrBacklight(true); // backlight on | |
jshDelayMicroseconds(10000); | |
#endif | |
@@ -3335,7 +3355,7 @@ bool jswrap_banglejs_idle() { | |
/*JSON{ | |
"type" : "EV_SERIAL1", | |
"generate" : "jswrap_banglejs_gps_character", | |
- "#if" : "defined(BANGLEJS_F18) || defined(DTNO1_F5) || defined(BANGLEJS_Q3)" | |
+ "#if" : "defined(GPS_PIN_RX) && (defined(BANGLEJS_F18) || defined(DTNO1_F5) || defined(BANGLEJS_Q3))" | |
}*/ | |
bool jswrap_banglejs_gps_character(char ch) { | |
// if too many chars, roll over since it's probably because we skipped a newline | |
diff --git a/targets/nrf5x/jshardware.c b/targets/nrf5x/jshardware.c | |
index e02ff7ae..bc69bb6f 100644 | |
--- a/targets/nrf5x/jshardware.c | |
+++ b/targets/nrf5x/jshardware.c | |
@@ -709,7 +709,21 @@ void jshResetPeripherals() { | |
#ifdef SPIFLASH_SLEEP_CMD | |
spiFlashWakeUp(); | |
#endif | |
+ | |
+ //Hardcode wakeup | |
+ { | |
+ unsigned char buf[1]; | |
+ buf[0] = 0x66; | |
+ spiFlashWriteCS(buf,1); | |
+ buf[0] = 0x99; | |
+ spiFlashWriteCS(buf,1); | |
+ nrf_delay_us(50); | |
+ buf[0] = 0xAB; | |
+ spiFlashWriteCS(buf,1); | |
+ nrf_delay_us(50); // datasheet tRES2 period > 20us CS remains high | |
+} | |
+ | |
// disable lock bits | |
// wait for write enable | |
unsigned char buf[2]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment