Skip to content

Commit

Permalink
Merge pull request #257 from brilliantlabsAR/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
siliconwitch authored Aug 7, 2023
2 parents 4c2d4ca + 2ef2673 commit 64c0327
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 23 deletions.
7 changes: 6 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,12 @@ static void touch_interrupt_handler(nrfx_gpiote_pin_t pin,
(void)polarity;

i2c_response_t interrupt = monocle_i2c_read(TOUCH_I2C_ADDRESS, 0x12, 0xFF);
app_err(interrupt.fail);

// Throw away interrupt if i2c is busy in another thread
if (interrupt.fail)
{
return;
}

switch (interrupt.value)
{
Expand Down
69 changes: 65 additions & 4 deletions modules/_splashscreen.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,69 @@
import fpga, display


def __splashscreen():
logo = display.Text(
"MONOCLE", 320, 200, display.WHITE, justify=display.MIDDLE_CENTER
)
bars_top = []
bars_bottom = []

starting_location = 185

ax = 68 + starting_location + 70
bx = 40 + starting_location + 70
cx = 0 + starting_location + 70
dx = 28 + starting_location + 70

for i in range(6):
if i == 0:
color = 0xFF0000
elif i == 1:
color = 0xFFAA00
elif i == 2:
color = 0xFFFF00
elif i == 3:
color = 0x008800
elif i == 4:
color = 0x0000FF
else:
color = 0xAA00FF

bars_top.append(display.Polygon([ax, 100, bx, 100, cx, 170, dx, 170], color))
ax += 28
bx += 28
cx += 28
dx += 28

ax = 68 + starting_location
bx = 40 + starting_location
cx = 0 + starting_location
dx = 28 + starting_location

for i in range(6):
if i == 0:
color = 0xFF0000
elif i == 1:
color = 0xFFAA00
elif i == 2:
color = 0xFFFF00
elif i == 3:
color = 0x008800
elif i == 4:
color = 0x0000FF
else:
color = 0xAA00FF

bars_bottom.append(display.Polygon([ax, 230, bx, 230, cx, 300, dx, 300], color))
ax += 28
bx += 28
cx += 28
dx += 28

display.show(logo, bars_top, bars_bottom)


if fpga.read(1, 4) == b"Mncl":
t = display.Text("MONOCLE", 320, 200, display.WHITE, justify=display.MIDDLE_CENTER)
display.show(t)
del t
__splashscreen()

del fpga, display
del fpga, display, __splashscreen
6 changes: 4 additions & 2 deletions modules/_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@

import device
import display
import camera

# import camera
import microphone
import touch
import led
Expand Down Expand Up @@ -203,11 +204,12 @@ def microphone_module():
def touch_module():
__test("touch.state('A')", False)
__test("touch.state('B')", False)
__test("touch.state('EITHER')", False)
__test("touch.state('BOTH')", False)
__test("touch.state(touch.A)", False)
__test("touch.state(touch.B)", False)
__test("touch.state(touch.EITHER)", False)
__test("touch.state(touch.BOTH)", False)
__test("touch.state('B')", False)
__test("callable(touch.callback)", True)


Expand Down
41 changes: 30 additions & 11 deletions modules/fpga.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,41 +105,60 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(fpga_run_obj, 0, 1, fpga_run);

STATIC mp_obj_t fpga_version(void)
{
uint8_t target_device[4];
uint8_t application_version[12];
uint8_t chip_revision[4];
uint8_t target_device[8];
uint8_t application_version[13];
uint8_t chip_revision[8];

memset(target_device, 0, sizeof(target_device));
memset(application_version, 0, sizeof(application_version));
memset(chip_revision, 0, sizeof(chip_revision));

uint8_t target_device_address[2] = {(uint8_t)(0x0001 >> 8), (uint8_t)0x0001};
uint8_t application_version_address[2] = {(uint8_t)(0x0002 >> 8), (uint8_t)0x0002};
uint8_t chip_revision_address[2] = {(uint8_t)(0x0003 >> 8), (uint8_t)0x0003};

monocle_spi_write(FPGA, target_device_address, 2, true);
monocle_spi_read(FPGA, target_device, sizeof(target_device), false);
monocle_spi_read(FPGA, target_device, 4, false);

monocle_spi_write(FPGA, application_version_address, 2, true);
monocle_spi_read(FPGA, application_version, sizeof(application_version), false);
monocle_spi_read(FPGA, application_version, 12, false);

monocle_spi_write(FPGA, chip_revision_address, 2, true);
monocle_spi_read(FPGA, chip_revision, sizeof(chip_revision), false);
monocle_spi_read(FPGA, chip_revision, 4, false);

// In case the chip is off, or has no image, nothing will be returned
if (target_device[0] == 0xff)
{
strcpy((char *)target_device, "unknown");
}
if (application_version[0] == 0xff)
{
strcpy((char *)application_version, "unknown");
}
if (chip_revision[0] == 0xff)
{
strcpy((char *)chip_revision, "unknown");
}

if (memcmp(chip_revision, "ffff", sizeof(chip_revision)) == 0)
// In case of legacy revC images, the register will return 'f' characters
if (memcmp(chip_revision, "ffff", 4) == 0)
{
memcpy(chip_revision, "revC", sizeof(chip_revision));
strcpy((char *)chip_revision, "revC");
}

mp_obj_t return_dict = mp_obj_new_dict(0);

mp_obj_dict_store(return_dict,
MP_OBJ_NEW_QSTR(MP_QSTR_target_device),
mp_obj_new_str((char *)target_device, sizeof(target_device)));
mp_obj_new_str((char *)target_device, strlen((char *)target_device)));

mp_obj_dict_store(return_dict,
MP_OBJ_NEW_QSTR(MP_QSTR_application_version),
mp_obj_new_str((char *)application_version, sizeof(application_version)));
mp_obj_new_str((char *)application_version, strlen((char *)application_version)));

mp_obj_dict_store(return_dict,
MP_OBJ_NEW_QSTR(MP_QSTR_chip_revision),
mp_obj_new_str((char *)chip_revision, sizeof(chip_revision)));
mp_obj_new_str((char *)chip_revision, strlen((char *)chip_revision)));

return return_dict;
}
Expand Down
7 changes: 7 additions & 0 deletions modules/led.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/

#include "py/mphal.h"
#include "py/runtime.h"
#include "monocle.h"

Expand All @@ -42,6 +43,9 @@ static mp_obj_t led_on(mp_obj_t led_in)
MP_ERROR_TEXT("must be led.RED or led.GREEN"));
}

// Unblocks i2c interrupts if led.on if called in an infinite loop
mp_hal_delay_ms(10);

if (led == MP_QSTR_RED)
{
monocle_set_led(RED_LED, true);
Expand All @@ -65,6 +69,9 @@ static mp_obj_t led_off(mp_obj_t led_in)
MP_ERROR_TEXT("must be led.RED or led.GREEN"));
}

// Unblocks i2c interrupts if led.on if called in an infinite loop
mp_hal_delay_ms(10);

if (led == MP_QSTR_RED)
{
monocle_set_led(RED_LED, false);
Expand Down
7 changes: 6 additions & 1 deletion monocle-core/monocle-critical.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ static void check_if_battery_charging_and_sleep(nrf_timer_event_t event_type,

// Get the CHG value from STAT_CHG_B
i2c_response_t charging_response = monocle_i2c_read(PMIC_I2C_ADDRESS, 0x03, 0x0C);
app_err(charging_response.fail);

// Avoid sleeping if i2c is busy in another thread . We can't handle this
if (charging_response.fail)
{
return;
}

bool charging = charging_response.value;

Expand Down
6 changes: 2 additions & 4 deletions monocle-core/monocle-drivers.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ i2c_response_t monocle_i2c_read(uint8_t device_address_7bit,
{
nrfx_err_t tx_err = nrfx_twim_xfer(&i2c_handle, &i2c_tx, 0);

if (tx_err == NRFX_ERROR_BUSY ||
tx_err == NRFX_ERROR_NOT_SUPPORTED ||
if (tx_err == NRFX_ERROR_NOT_SUPPORTED ||
tx_err == NRFX_ERROR_INTERNAL ||
tx_err == NRFX_ERROR_INVALID_ADDR ||
tx_err == NRFX_ERROR_DRV_TWI_ERR_OVERRUN)
Expand All @@ -115,8 +114,7 @@ i2c_response_t monocle_i2c_read(uint8_t device_address_7bit,

nrfx_err_t rx_err = nrfx_twim_xfer(&i2c_handle, &i2c_rx, 0);

if (rx_err == NRFX_ERROR_BUSY ||
rx_err == NRFX_ERROR_NOT_SUPPORTED ||
if (rx_err == NRFX_ERROR_NOT_SUPPORTED ||
rx_err == NRFX_ERROR_INTERNAL ||
rx_err == NRFX_ERROR_INVALID_ADDR ||
rx_err == NRFX_ERROR_DRV_TWI_ERR_OVERRUN)
Expand Down

0 comments on commit 64c0327

Please sign in to comment.