trying to squash some warnings, fix I2C tx

This commit is contained in:
Gordon Williams 2016-01-14 13:43:00 +00:00
parent f78194fe6b
commit 53593090d2
2 changed files with 17 additions and 17 deletions

View File

@ -103,11 +103,11 @@ void jswrap_microbit_stopDisplay() {
}*/
void jswrap_microbit_init() {
// enable I2C (for accelerometers, etc)
/*JshI2CInfo inf;
JshI2CInfo inf;
jshI2CInitInfo(&inf);
inf.pinSCL = jshGetPinFromString('D19');
inf.pinSDA = jshGetPinFromString('D20');
jshI2CSetup(EV_I2C1, &inf);*/
inf.pinSCL = JSH_PORTD_OFFSET+19; // 'D19'
inf.pinSDA = JSH_PORTD_OFFSET+20; // 'D20'
jshI2CSetup(EV_I2C1, &inf);
}
/*JSON{
@ -172,15 +172,15 @@ void jswrap_microbit_show(JsVar *image) {
Get the current acceleration of the micro:bit
*/
JsVar *jswrap_microbit_acceleration() {
char d[6];
unsigned char d[6];
d[0] = 1;
jshI2CWrite(EV_I2C1, 0x1D, 1, &d, true);
jshI2CRead(EV_I2C1, 0x1D, 6, &d, true);
jshI2CWrite(EV_I2C1, 0x1D, 1, d, true);
jshI2CRead(EV_I2C1, 0x1D, 6, d, true);
JsVar *xyz = jsvNewWithFlags(JSV_OBJECT);
if (xyz) {
int16_t x = (int16_t)(d[0]<<8 | d[1]);
int16_t y = (int16_t)(d[2]<<8 | d[3]);
int16_t z = (int16_t)(d[4]<<8 | d[5]);
int16_t x = (int16_t)((d[0]<<8) | d[1]);
int16_t y = (int16_t)((d[2]<<8) | d[3]);
int16_t z = (int16_t)((d[4]<<8) | d[5]);
jsvObjectSetChildAndUnLock(xyz, "x", jsvNewFromFloat(x / 16384.0));
jsvObjectSetChildAndUnLock(xyz, "y", jsvNewFromFloat(y / 16384.0));
jsvObjectSetChildAndUnLock(xyz, "z", jsvNewFromFloat(z / 16384.0));

View File

@ -420,8 +420,8 @@ void jshUSARTSetup(IOEventFlags device, JshUSARTInfo *inf) {
const app_uart_comm_params_t comm_params = {
pinInfo[inf->pinRX].pin,
pinInfo[inf->pinTX].pin,
UART_PIN_DISCONNECTED,
UART_PIN_DISCONNECTED,
(uint8_t)UART_PIN_DISCONNECTED,
(uint8_t)UART_PIN_DISCONNECTED,
APP_UART_FLOW_CONTROL_DISABLED,
inf->parity!=0, // TODO: ODD or EVEN parity?
baud
@ -491,7 +491,7 @@ void jshSPIWait(IOEventFlags device) {
const nrf_drv_twi_t TWI1 = NRF_DRV_TWI_INSTANCE(1);
nrf_drv_twi_t *jshGetTWI(IOEventFlags device) {
const nrf_drv_twi_t *jshGetTWI(IOEventFlags device) {
if (device == EV_I2C1) return &TWI1;
return 0;
}
@ -502,7 +502,7 @@ void jshI2CSetup(IOEventFlags device, JshI2CInfo *inf) {
jsError("SDA and SCL pins must be valid, got %d and %d\n", inf->pinSDA, inf->pinSCL);
return;
}
nrf_drv_twi_t *twi = jshGetTWI(device);
const nrf_drv_twi_t *twi = jshGetTWI(device);
if (!twi) return;
// http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk51.v9.0.0%2Fhardware_driver_twi.html&cp=4_1_0_2_10
nrf_drv_twi_config_t p_twi_config;
@ -519,15 +519,15 @@ void jshI2CSetup(IOEventFlags device, JshI2CInfo *inf) {
/** Addresses are 7 bit - that is, between 0 and 0x7F. sendStop is whether to send a stop bit or not */
void jshI2CWrite(IOEventFlags device, unsigned char address, int nBytes, const unsigned char *data, bool sendStop) {
nrf_drv_twi_t *twi = jshGetTWI(device);
const nrf_drv_twi_t *twi = jshGetTWI(device);
if (!twi) return;
uint32_t err_code = nrf_drv_twi_rx(twi, address, data, nBytes, !sendStop);
uint32_t err_code = nrf_drv_twi_tx(twi, address, data, nBytes, !sendStop);
if (err_code != NRF_SUCCESS)
jsExceptionHere(JSET_INTERNALERROR, "I2C Write Error %d\n", err_code);
}
void jshI2CRead(IOEventFlags device, unsigned char address, int nBytes, unsigned char *data, bool sendStop) {
nrf_drv_twi_t *twi = jshGetTWI(device);
const nrf_drv_twi_t *twi = jshGetTWI(device);
if (!twi) return;
uint32_t err_code = nrf_drv_twi_rx(twi, address, data, nBytes, !sendStop);
if (err_code != NRF_SUCCESS)