mirror of
https://github.com/espruino/Espruino.git
synced 2025-12-08 19:06:15 +00:00
First hack at microbit2 port
This commit is contained in:
parent
be61b5139e
commit
f0d60a0831
132
boards/MICROBIT2.py
Normal file
132
boards/MICROBIT2.py
Normal file
@ -0,0 +1,132 @@
|
||||
#!/bin/false
|
||||
# This file is part of Espruino, a JavaScript interpreter for Microcontrollers
|
||||
#
|
||||
# Copyright (C) 2013 Gordon Williams <gw@pur3.co.uk>
|
||||
#
|
||||
# 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 contains information for a specific board - the available pins, and where LEDs,
|
||||
# Buttons, and other in-built peripherals are. It is used to build documentation as well
|
||||
# as various source and header files for Espruino.
|
||||
# ----------------------------------------------------------------------------------------
|
||||
|
||||
import pinutils;
|
||||
|
||||
info = {
|
||||
'name' : "BBC micro:bit 2",
|
||||
'link' : [ "https://en.wikipedia.org/wiki/Micro_Bit" ],
|
||||
'espruino_page_link' : 'MicroBit',
|
||||
# This is the PCA10036
|
||||
'default_console' : "EV_SERIAL1",
|
||||
'default_console_tx' : "H1",
|
||||
'default_console_rx' : "H0",
|
||||
'default_console_baudrate' : "9600",
|
||||
'variables' : 2050, # How many variables are allocated for Espruino to use. RAM will be overflowed if this number is too high and code won't compile.
|
||||
'binary_name' : 'espruino_%v_microbit2.hex',
|
||||
'build' : {
|
||||
'optimizeflags' : '-Os',
|
||||
'libraries' : [
|
||||
'BLUETOOTH',
|
||||
# 'NET',
|
||||
'GRAPHICS',
|
||||
'NEOPIXEL',
|
||||
'TENSORFLOW'
|
||||
],
|
||||
'makefile' : [
|
||||
'DEFINES += -DCONFIG_GPIO_AS_PINRESET', # Allow the reset pin to work
|
||||
'DEFINES += -DGPIO_COUNT=2 -DP1_PIN_NUM=16 -DNRF_P1_BASE=0x50000300UL "-DNRF_P1=((NRF_GPIO_Type*)NRF_P1_BASE)"', # Hack for 52833 on SDK12
|
||||
'DEFINES += -DMICROBIT', # enable microbit-specific stuff
|
||||
'INCLUDE += -I$(ROOT)/libs/microbit',
|
||||
'WRAPPERSOURCES += libs/microbit/jswrap_microbit.c',
|
||||
'DEFINES+=-DNEOPIXEL_SCK_PIN=27' # an unused pin
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
chip = {
|
||||
'part' : "NRF52832", # actually 52833 but we're using SDK12 for this at the moment, and it doesn't support it
|
||||
'family' : "NRF52",
|
||||
'package' : "QFN48",
|
||||
'ram' : 64,
|
||||
'flash' : 512,
|
||||
'speed' : 64,
|
||||
'usart' : 1,
|
||||
'spi' : 1,
|
||||
'i2c' : 1,
|
||||
'adc' : 1,
|
||||
'dac' : 0,
|
||||
'saved_code' : {
|
||||
'address' : ((118 - 10) * 4096), # Bootloader takes pages 120-127, FS takes 118-119
|
||||
'page_size' : 4096,
|
||||
'pages' : 10,
|
||||
'flash_available' : 512 - ((31 + 8 + 2 + 10)*4) # Softdevice uses 31 pages of flash, bootloader 8, FS 2, code 10. Each page is 4 kb.
|
||||
},
|
||||
};
|
||||
|
||||
devices = {
|
||||
'BTN1' : { 'pin' : 'D5', 'pinstate' : 'IN_PULLDOWN' }, # Pin negated in software
|
||||
'BTN2' : { 'pin' : 'D11', 'pinstate' : 'IN_PULLDOWN' }, # Pin negated in software
|
||||
# 'BTN3' : { 'pin' : 'H2', 'pinstate' : 'IN' }, # Pin negated in software
|
||||
# 'V' pins are virtual
|
||||
'LED1' : { 'pin' : 'V0' },
|
||||
};
|
||||
|
||||
# left-right, or top-bottom order
|
||||
board = {
|
||||
};
|
||||
board["_css"] = """
|
||||
""";
|
||||
|
||||
def get_pins():
|
||||
pins = [
|
||||
{ "name":"PD0", "sortingname":"D00", "port":"D", "num":"2", "functions":{ "ADC1_IN0":0 }, "csv":{} }, # RING0
|
||||
{ "name":"PD1", "sortingname":"D01", "port":"D", "num":"3", "functions":{ "ADC1_IN1":0 }, "csv":{} }, # RING1
|
||||
{ "name":"PD2", "sortingname":"D02", "port":"D", "num":"4", "functions":{ "ADC1_IN2":0 }, "csv":{} }, # RING2
|
||||
{ "name":"PD3", "sortingname":"D03", "port":"D", "num":"31", "functions":{ }, "csv":{} }, # COLR3
|
||||
{ "name":"PD4", "sortingname":"D04", "port":"D", "num":"28", "functions":{ }, "csv":{} }, # COLR1
|
||||
{ "name":"PD5", "sortingname":"D05", "port":"D", "num":"14", "functions":{}, "csv":{} }, # BTN1
|
||||
{ "name":"PD6", "sortingname":"D06", "port":"D", "num":"37", "functions":{}, "csv":{} }, # COLR4
|
||||
{ "name":"PD7", "sortingname":"D07", "port":"D", "num":"11", "functions":{}, "csv":{} }, # COLR2
|
||||
{ "name":"PD8", "sortingname":"D08", "port":"D", "num":"10", "functions":{}, "csv":{} }, # GPIO1
|
||||
{ "name":"PD9", "sortingname":"D09", "port":"D", "num":"9", "functions":{}, "csv":{} }, # GPIO2
|
||||
{ "name":"PD10", "sortingname":"D10", "port":"D", "num":"30", "functions":{ }, "csv":{} }, # COLR5
|
||||
{ "name":"PD11", "sortingname":"D11", "port":"D", "num":"23", "functions":{ }, "csv":{} }, # BTN2
|
||||
{ "name":"PD12", "sortingname":"D12", "port":"D", "num":"12", "functions":{}, "csv":{} }, # GPIO4
|
||||
{ "name":"PD13", "sortingname":"D13", "port":"D", "num":"17", "functions":{ "SPI1_SCK":0 }, "csv":{} },
|
||||
{ "name":"PD14", "sortingname":"D14", "port":"D", "num":"1", "functions":{ "SPI1_MISO":0 }, "csv":{} },
|
||||
{ "name":"PD15", "sortingname":"D15", "port":"D", "num":"13", "functions":{ "SPI1_MOSI":0 }, "csv":{} },
|
||||
{ "name":"PD16", "sortingname":"D16", "port":"D", "num":"34", "functions":{}, "csv":{} }, # GPIO3
|
||||
{ "name":"PD17", "sortingname":"D17", "port":"D", "num":"27", "functions":{}, "csv":{} }, # FIXME 3.3v - using an unused pin
|
||||
{ "name":"PD18", "sortingname":"D18", "port":"D", "num":"27", "functions":{}, "csv":{} }, # FIXME 3.3v - using an unused pin
|
||||
{ "name":"PD19", "sortingname":"D19", "port":"D", "num":"26", "functions":{ "I2C1_SCL":0 }, "csv":{} },
|
||||
{ "name":"PD20", "sortingname":"D20", "port":"D", "num":"32", "functions":{ "I2C1_SDA":0 }, "csv":{} },
|
||||
{ "name":"PH0", "sortingname":"H00", "port":"H", "num":"40", "functions":{"USART1_RX" : 0}, "csv":{} }, # UART_RX - receive into Espruino
|
||||
{ "name":"PH1", "sortingname":"H01", "port":"H", "num":"6", "functions":{"USART1_TX" : 0}, "csv":{} }, # UART_TX
|
||||
{ "name":"PH2", "sortingname":"H02", "port":"H", "num":"36", "functions":{}, "csv":{} }, # face touch
|
||||
{ "name":"PH3", "sortingname":"H03", "port":"H", "num":"0", "functions":{}, "csv":{} }, # speaker
|
||||
{ "name":"PH4", "sortingname":"H04", "port":"H", "num":"5", "functions":{ "ADC1_IN0":3 }, "csv":{} }, # mic_in
|
||||
{ "name":"PH5", "sortingname":"H05", "port":"H", "num":"20", "functions":{}, "csv":{} }, # run_mic
|
||||
{ "name":"PH6", "sortingname":"H06", "port":"H", "num":"16", "functions":{}, "csv":{} }, # INT_SDA
|
||||
{ "name":"PH7", "sortingname":"H07", "port":"H", "num":"8", "functions":{}, "csv":{} }, # INT_SCL
|
||||
{ "name":"PH8", "sortingname":"H08", "port":"H", "num":"25", "functions":{}, "csv":{} }, # INT
|
||||
{ "name":"PV0", "sortingname":"V0", "port":"V", "num":"0", "functions":{}, "csv":{} } # LED virtual pin
|
||||
];
|
||||
#21 # ROW1
|
||||
#22 # ROW2
|
||||
#15 # ROW3
|
||||
#24 # ROW4
|
||||
#19 # ROW5
|
||||
|
||||
# Make buttons negated
|
||||
pinutils.findpin(pins, "PD5", True)["functions"]["NEGATED"]=0;
|
||||
pinutils.findpin(pins, "PD11", True)["functions"]["NEGATED"]=0;
|
||||
|
||||
# everything is non-5v tolerant
|
||||
for pin in pins:
|
||||
pin["functions"]["3.3"]=0;
|
||||
#The boot/reset button will function as a reset button in normal operation. Pin reset on PD21 needs to be enabled on the nRF52832 device for this to work.
|
||||
return pins
|
||||
@ -22,36 +22,13 @@
|
||||
|
||||
#include "nrf_gpio.h" // just go direct
|
||||
|
||||
/*
|
||||
|
||||
g = Graphics.createArrayBuffer(5,5,1);
|
||||
g.drawString("E");
|
||||
show((new Uint32Array(g.buffer))[0])
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
uint32_t microbitLEDState = 0;
|
||||
uint8_t microbitRow = 0;
|
||||
|
||||
// Do we have the new version with the different magnetometer?
|
||||
bool microbitLSM303;
|
||||
|
||||
// real NRF pins 4,5,6,7,8,9,10,11,12 (column pull down)
|
||||
// real NRF pins 13,14,15 (row pull up)
|
||||
static const int MB_LED_COL1 = 4;
|
||||
static const int MB_LED_COL2 = 5;
|
||||
static const int MB_LED_COL3 = 6;
|
||||
static const int MB_LED_COL4 = 7;
|
||||
static const int MB_LED_COL5 = 8;
|
||||
static const int MB_LED_COL6 = 9;
|
||||
static const int MB_LED_COL7 = 10;
|
||||
static const int MB_LED_COL8 = 11;
|
||||
static const int MB_LED_COL9 = 12;
|
||||
static const int MB_LED_ROW1 = 13;
|
||||
static const int MB_LED_ROW2 = 14;
|
||||
static const int MB_LED_ROW3 = 15;
|
||||
#ifdef MICROBIT2
|
||||
#include "jsi2c.h" // accelerometer/etc
|
||||
// we use software I2C
|
||||
JshI2CInfo i2cInfo;
|
||||
// All microbit 2's have the new mmagnetometer
|
||||
const bool microbitLSM303 = true;
|
||||
#else
|
||||
|
||||
// 32 means not used
|
||||
static const uint8_t MB_LED_MAPPING[] = {
|
||||
@ -62,14 +39,42 @@ static const uint8_t MB_LED_MAPPING[] = {
|
||||
|
||||
const int MMA8652_ADDR = 0x1D;
|
||||
const int MAG3110_ADDR = 0x0E;
|
||||
|
||||
// Do we have the new version with the different magnetometer?
|
||||
bool microbitLSM303;
|
||||
#endif
|
||||
|
||||
const int LSM303_ACC_ADDR = 0b0011001;
|
||||
const int LSM303_MAG_ADDR = 0b0011110;
|
||||
|
||||
uint32_t microbitLEDState = 0;
|
||||
uint8_t microbitRow = 0;
|
||||
|
||||
// called on a timer to scan rows out
|
||||
void jswrap_microbit_display_callback() {
|
||||
|
||||
#ifdef MICROBIT2
|
||||
microbitRow++;
|
||||
if (microbitRow>5) microbitRow=0;
|
||||
uint32_t s = (~microbitLEDState) >> microbitRow*5;
|
||||
nrf_gpio_pin_clear(MB_LED_ROW1);
|
||||
nrf_gpio_pin_clear(MB_LED_ROW2);
|
||||
nrf_gpio_pin_clear(MB_LED_ROW3);
|
||||
nrf_gpio_pin_clear(MB_LED_ROW4);
|
||||
nrf_gpio_pin_clear(MB_LED_ROW5);
|
||||
nrf_gpio_pin_write(MB_LED_COL1, s & 1);
|
||||
nrf_gpio_pin_write(MB_LED_COL2, s & 2);
|
||||
nrf_gpio_pin_write(MB_LED_COL3, s & 4);
|
||||
nrf_gpio_pin_write(MB_LED_COL4, s & 8);
|
||||
nrf_gpio_pin_write(MB_LED_COL5, s & 16);
|
||||
nrf_gpio_pin_write(MB_LED_ROW1, microbitRow==0);
|
||||
nrf_gpio_pin_write(MB_LED_ROW2, microbitRow==1);
|
||||
nrf_gpio_pin_write(MB_LED_ROW3, microbitRow==2);
|
||||
nrf_gpio_pin_write(MB_LED_ROW4, microbitRow==3);
|
||||
nrf_gpio_pin_write(MB_LED_ROW5, microbitRow==4);
|
||||
#else
|
||||
microbitRow++;
|
||||
if (microbitRow>2) microbitRow=0;
|
||||
|
||||
int n = microbitRow*9;
|
||||
uint32_t s = ~microbitLEDState;
|
||||
nrf_gpio_pin_clear(MB_LED_ROW1);
|
||||
@ -87,6 +92,7 @@ void jswrap_microbit_display_callback() {
|
||||
nrf_gpio_pin_write(MB_LED_ROW1, microbitRow==0);
|
||||
nrf_gpio_pin_write(MB_LED_ROW2, microbitRow==1);
|
||||
nrf_gpio_pin_write(MB_LED_ROW3, microbitRow==2);
|
||||
#endif
|
||||
}
|
||||
|
||||
void jswrap_microbit_stopDisplay() {
|
||||
@ -99,58 +105,90 @@ void jswrap_microbit_stopDisplay() {
|
||||
nrf_gpio_cfg_default(MB_LED_COL3);
|
||||
nrf_gpio_cfg_default(MB_LED_COL4);
|
||||
nrf_gpio_cfg_default(MB_LED_COL5);
|
||||
#ifdef MICROBIT2
|
||||
nrf_gpio_cfg_default(MB_LED_ROW4);
|
||||
nrf_gpio_cfg_default(MB_LED_ROW5);
|
||||
#else
|
||||
nrf_gpio_cfg_default(MB_LED_COL6);
|
||||
nrf_gpio_cfg_default(MB_LED_COL7);
|
||||
nrf_gpio_cfg_default(MB_LED_COL8);
|
||||
nrf_gpio_cfg_default(MB_LED_COL9);
|
||||
#endif
|
||||
nrf_gpio_cfg_default(MB_LED_ROW1);
|
||||
nrf_gpio_cfg_default(MB_LED_ROW2);
|
||||
nrf_gpio_cfg_default(MB_LED_ROW3);
|
||||
}
|
||||
}
|
||||
|
||||
void mb_i2c_write(unsigned int addr, int count, const unsigned char *data) {
|
||||
#ifdef MICROBIT2
|
||||
jsi2cWrite(&i2cInfo, addr, count, data, true);
|
||||
#else
|
||||
jshI2CWrite(EV_I2C1, addr, count, data, true);
|
||||
#endif
|
||||
}
|
||||
void mb_i2c_read(unsigned int addr, int count, unsigned char *data) {
|
||||
#ifdef MICROBIT2
|
||||
jsi2cRead(&i2cInfo, addr, count, data, true);
|
||||
#else
|
||||
jshI2CRead(EV_I2C1, addr, count, data, true);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*JSON{
|
||||
"type" : "init",
|
||||
"generate" : "jswrap_microbit_init"
|
||||
}*/
|
||||
void jswrap_microbit_init() {
|
||||
// enable I2C (for accelerometers, etc)
|
||||
JshI2CInfo inf;
|
||||
jshI2CInitInfo(&inf);
|
||||
inf.pinSCL = JSH_PORTD_OFFSET+19; // 'D19'
|
||||
inf.pinSDA = JSH_PORTD_OFFSET+20; // 'D20'
|
||||
jshI2CSetup(EV_I2C1, &inf);
|
||||
#ifndef MICROBIT2
|
||||
JshI2CInfo i2cInfo;
|
||||
#endif
|
||||
jshI2CInitInfo(&i2cInfo);
|
||||
#ifdef MICROBIT2
|
||||
i2cInfo.bitrate = 0x7FFFFFFF; // make it as fast as we can go
|
||||
i2cInfo.clockStretch = false;
|
||||
#endif
|
||||
i2cInfo.pinSCL = INTERNAL_I2C_SCL_PIN;
|
||||
i2cInfo.pinSDA = INTERNAL_I2C_SDA_PIN;
|
||||
jshI2CSetup(EV_I2C1, &i2cInfo);
|
||||
|
||||
unsigned char d[2];
|
||||
#ifndef MICROBIT2
|
||||
d[0] = 0x07; // WHO_AM_I
|
||||
jshI2CWrite(EV_I2C1, MAG3110_ADDR, 1, d, true);
|
||||
jshI2CRead(EV_I2C1, MAG3110_ADDR, 1, d, true);
|
||||
mb_i2c_write(MAG3110_ADDR, 1, d);
|
||||
mb_i2c_read(MAG3110_ADDR, 1, d);
|
||||
jsvUnLock(jspGetException());
|
||||
if (d[0]==0xC4) {
|
||||
microbitLSM303 = false;
|
||||
// Enable MMA8652 Accelerometer
|
||||
d[0] = 0x2A; d[1] = 0x19; // CTRL_REG1, 100Hz, turn on
|
||||
jshI2CWrite(EV_I2C1, MMA8652_ADDR, 2, d, true);
|
||||
mb_i2c_write(MMA8652_ADDR, 2, d);
|
||||
// Enable MAG3110 magnetometer, 80Hz
|
||||
d[0] = 0x11; d[1] = 0x80; // CTRL_REG2, AUTO_MRST_EN
|
||||
jshI2CWrite(EV_I2C1, MAG3110_ADDR, 2, d, true);
|
||||
mb_i2c_write(MAG3110_ADDR, 2, d);
|
||||
d[0] = 0x10; d[1] = 0x01; // CTRL_REG1, active mode 80 Hz ODR with OSR = 1
|
||||
jshI2CWrite(EV_I2C1, MAG3110_ADDR, 2, d, true);
|
||||
mb_i2c_write(MAG3110_ADDR, 2, d);
|
||||
#else
|
||||
if (false) {
|
||||
#endif
|
||||
} else {
|
||||
#ifndef MICROBIT2
|
||||
microbitLSM303 = true;
|
||||
#endif
|
||||
// LSM303_ACC_ADDR,0x0F => 51 // WHO_AM_I
|
||||
// Init accelerometer
|
||||
d[0] = 0x20; d[1] = 0b00110111; // CTRL_REG1_A, 25Hz
|
||||
jshI2CWrite(EV_I2C1, LSM303_ACC_ADDR, 2, d, true);
|
||||
mb_i2c_write(LSM303_ACC_ADDR, 2, d);
|
||||
d[0] = 0x22; d[1] = 0x10; // CTRL_REG3_A
|
||||
jshI2CWrite(EV_I2C1, LSM303_ACC_ADDR, 2, d, true);
|
||||
mb_i2c_write(LSM303_ACC_ADDR, 2, d);
|
||||
d[0] = 0x23; d[1] = 0b11011000; // CTRL_REG4_A - 4g range, MSB at low address, high res
|
||||
jshI2CWrite(EV_I2C1, LSM303_ACC_ADDR, 2, d, true);
|
||||
mb_i2c_write(LSM303_ACC_ADDR, 2, d);
|
||||
// Init magnetometer
|
||||
d[0] = 0x60; d[1] = 0x04; // CFG_REG_A_M, 20Hz
|
||||
jshI2CWrite(EV_I2C1, LSM303_MAG_ADDR, 2, d, true);
|
||||
mb_i2c_write(LSM303_MAG_ADDR, 2, d);
|
||||
d[0] = 0x62; d[1] = 0b00001001; // CFG_REG_C_M - enable data ready IRQ (not that we use this), swap block order to match MAG3110
|
||||
jshI2CWrite(EV_I2C1, LSM303_MAG_ADDR, 2, d, true);
|
||||
mb_i2c_write(LSM303_MAG_ADDR, 2, d);
|
||||
}
|
||||
}
|
||||
|
||||
@ -213,10 +251,15 @@ void jswrap_microbit_show_raw(uint32_t newState) {
|
||||
nrf_gpio_cfg_output(MB_LED_COL3);
|
||||
nrf_gpio_cfg_output(MB_LED_COL4);
|
||||
nrf_gpio_cfg_output(MB_LED_COL5);
|
||||
#ifdef MICROBIT2
|
||||
nrf_gpio_cfg_output(MB_LED_ROW4);
|
||||
nrf_gpio_cfg_output(MB_LED_ROW5);
|
||||
#else
|
||||
nrf_gpio_cfg_output(MB_LED_COL6);
|
||||
nrf_gpio_cfg_output(MB_LED_COL7);
|
||||
nrf_gpio_cfg_output(MB_LED_COL8);
|
||||
nrf_gpio_cfg_output(MB_LED_COL9);
|
||||
#endif
|
||||
nrf_gpio_cfg_output(MB_LED_ROW1);
|
||||
nrf_gpio_cfg_output(MB_LED_ROW2);
|
||||
nrf_gpio_cfg_output(MB_LED_ROW3);
|
||||
@ -275,14 +318,16 @@ JsVar *jswrap_microbit_acceleration() {
|
||||
JsVarFloat range;
|
||||
if (microbitLSM303) {
|
||||
d[0] = 0x28 | 0x80;
|
||||
jshI2CWrite(EV_I2C1, LSM303_ACC_ADDR, 1, d, true);
|
||||
jshI2CRead(EV_I2C1, LSM303_ACC_ADDR, 6, &d[1], true);
|
||||
mb_i2c_write(LSM303_ACC_ADDR, 1, d);
|
||||
mb_i2c_read(LSM303_ACC_ADDR, 6, &d[1]);
|
||||
range = 8192;
|
||||
} else {
|
||||
#ifndef MICROBIT2
|
||||
d[0] = 1;
|
||||
jshI2CWrite(EV_I2C1, MMA8652_ADDR, 1, d, true);
|
||||
jshI2CRead(EV_I2C1, MMA8652_ADDR, 7, d, true);
|
||||
mb_i2c_write(MMA8652_ADDR, 1, d);
|
||||
mb_i2c_read(MMA8652_ADDR, 7, d);
|
||||
range = 16384;
|
||||
#endif
|
||||
}
|
||||
JsVar *xyz = jsvNewObject();
|
||||
if (xyz) {
|
||||
@ -315,12 +360,14 @@ JsVar *jswrap_microbit_compass() {
|
||||
unsigned char d[6];
|
||||
if (microbitLSM303) {
|
||||
d[0] = 0x68 | 0x80;
|
||||
jshI2CWrite(EV_I2C1, LSM303_MAG_ADDR, 1, d, true);
|
||||
jshI2CRead(EV_I2C1, LSM303_MAG_ADDR, 6, d, true);
|
||||
mb_i2c_write(LSM303_MAG_ADDR, 1, d);
|
||||
mb_i2c_read(LSM303_MAG_ADDR, 6, d);
|
||||
} else {
|
||||
#ifndef MICROBIT2
|
||||
d[0] = 1;
|
||||
jshI2CWrite(EV_I2C1, MAG3110_ADDR, 1, d, true);
|
||||
jshI2CRead(EV_I2C1, MAG3110_ADDR, 6, d, true);
|
||||
mb_i2c_write(MAG3110_ADDR, 1, d);
|
||||
mb_i2c_read(MAG3110_ADDR, 6, d);
|
||||
#endif
|
||||
}
|
||||
JsVar *xyz = jsvNewObject();
|
||||
if (xyz) {
|
||||
@ -338,6 +385,36 @@ JsVar *jswrap_microbit_compass() {
|
||||
}
|
||||
|
||||
|
||||
/*JSON{
|
||||
"type" : "variable",
|
||||
"name" : "SPEAKER",
|
||||
"generate_full" : "SPEAKER_PIN",
|
||||
"ifdef" : "MICROBIT2",
|
||||
"return" : ["pin",""]
|
||||
}
|
||||
The micro:bit's speaker
|
||||
*/
|
||||
/*JSON{
|
||||
"type" : "variable",
|
||||
"name" : "MIC",
|
||||
"generate_full" : "MIC_PIN",
|
||||
"ifdef" : "MICROBIT2",
|
||||
"return" : ["pin",""]
|
||||
}
|
||||
The micro:bit's microphone
|
||||
|
||||
`MIC_ENABLE` should be set to 1 before using this
|
||||
*/
|
||||
/*JSON{
|
||||
"type" : "variable",
|
||||
"name" : "MIC_ENABLE",
|
||||
"generate_full" : "MIC_ENABLE_PIN",
|
||||
"ifdef" : "MICROBIT2",
|
||||
"return" : ["pin",""]
|
||||
}
|
||||
The micro:bit's microphone enable pin
|
||||
*/
|
||||
|
||||
//------------------------ virtuial pins allow us to have a LED1
|
||||
void jshVirtualPinInitialise() {
|
||||
}
|
||||
|
||||
@ -14,6 +14,46 @@
|
||||
|
||||
#include "jsvar.h"
|
||||
|
||||
#ifdef MICROBIT2
|
||||
#define SPEAKER_PIN (JSH_PORTH_OFFSET+3)
|
||||
#define MIC_PIN (JSH_PORTH_OFFSET+4)
|
||||
#define MIC_ENABLE_PIN (JSH_PORTH_OFFSET+5)
|
||||
#define MIC_ENABLE_PIN (JSH_PORTH_OFFSET+5)
|
||||
#define INTERNAL_I2C_SCL_PIN (JSH_PORTH_OFFSET+7)
|
||||
#define INTERNAL_I2C_SDA_PIN (JSH_PORTH_OFFSET+6)
|
||||
|
||||
// real NRF pins for row (pull up) / column (pull down)
|
||||
#define MB_LED_COL1 (28)
|
||||
#define MB_LED_COL2 (11)
|
||||
#define MB_LED_COL3 (31)
|
||||
#define MB_LED_COL4 (37)
|
||||
#define MB_LED_COL5 (30)
|
||||
#define MB_LED_ROW1 (21)
|
||||
#define MB_LED_ROW2 (22)
|
||||
#define MB_LED_ROW3 (15)
|
||||
#define MB_LED_ROW4 (24)
|
||||
#define MB_LED_ROW5 (19)
|
||||
|
||||
#else // MICROBIT1
|
||||
#define INTERNAL_I2C_SCL_PIN (JSH_PORTD_OFFSET+19)
|
||||
#define INTERNAL_I2C_SDA_PIN (JSH_PORTD_OFFSET+20)
|
||||
|
||||
// real NRF pins 4,5,6,7,8,9,10,11,12 (column pull down)
|
||||
// real NRF pins 13,14,15 (row pull up)
|
||||
#define MB_LED_COL1 (4)
|
||||
#define MB_LED_COL2 (5)
|
||||
#define MB_LED_COL3 (6)
|
||||
#define MB_LED_COL4 (7)
|
||||
#define MB_LED_COL5 (8)
|
||||
#define MB_LED_COL6 (9)
|
||||
#define MB_LED_COL7 (10)
|
||||
#define MB_LED_COL8 (11)
|
||||
#define MB_LED_COL9 (12)
|
||||
#define MB_LED_ROW1 (13)
|
||||
#define MB_LED_ROW2 (14)
|
||||
#define MB_LED_ROW3 (15)
|
||||
#endif
|
||||
|
||||
void jswrap_microbit_init();
|
||||
void jswrap_microbit_kill();
|
||||
void jswrap_microbit_show(JsVar *image);
|
||||
|
||||
@ -50,7 +50,9 @@
|
||||
|
||||
/* GPIO */
|
||||
#define GPIO_PRESENT
|
||||
#ifndef GPIO_COUNT
|
||||
#define GPIO_COUNT 1
|
||||
#endif
|
||||
|
||||
#define P0_PIN_NUM 32
|
||||
|
||||
|
||||
@ -82,6 +82,9 @@ void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info) {
|
||||
#if NRF_SD_BLE_API_VERSION<5
|
||||
#include "softdevice_handler.h"
|
||||
#endif
|
||||
#ifdef MICROBIT
|
||||
#include "jswrap_microbit.h"
|
||||
#endif
|
||||
|
||||
void WDT_IRQHandler() {
|
||||
}
|
||||
@ -633,17 +636,23 @@ void jshInit() {
|
||||
jshDelayMicroseconds(10);
|
||||
|
||||
#ifdef MICROBIT
|
||||
nrf_gpio_pin_set(MB_LED_ROW1);
|
||||
/* We must wait ~1 second for the USB interface to initialise
|
||||
* or it won't raise the RX pin and we won't think anything
|
||||
* is connected. */
|
||||
bool waitForUART = !jshPinGetValue(DEFAULT_CONSOLE_RX_PIN);
|
||||
for (int i=0;i<10 && !jshPinGetValue(DEFAULT_CONSOLE_RX_PIN);i++) {
|
||||
nrf_gpio_pin_write(MB_LED_COL1, i&1);
|
||||
nrf_delay_ms(100);
|
||||
ticksSinceStart = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef MICROBIT2
|
||||
if (true) {
|
||||
#else
|
||||
if (jshPinGetValue(DEFAULT_CONSOLE_RX_PIN)) {
|
||||
#endif
|
||||
JshUSARTInfo inf;
|
||||
jshUSARTInitInfo(&inf);
|
||||
inf.pinRX = DEFAULT_CONSOLE_RX_PIN;
|
||||
@ -657,6 +666,7 @@ void jshInit() {
|
||||
* the UART wasn't powered when we connected. */
|
||||
if (waitForUART) {
|
||||
for (int i=0;i<30;i++) {
|
||||
nrf_gpio_pin_write(MB_LED_COL2, i&1);
|
||||
nrf_delay_ms(100);
|
||||
ticksSinceStart = 0;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user