summaryrefslogtreecommitdiffstatshomepage
path: root/stm
diff options
context:
space:
mode:
Diffstat (limited to 'stm')
-rw-r--r--stm/audio.c2
-rw-r--r--stm/cc3k/pybcc3k.c6
-rw-r--r--stm/i2c.c83
-rw-r--r--stm/led.c11
-rw-r--r--stm/lexerstm.c2
-rw-r--r--stm/lexerstm.h4
-rw-r--r--stm/main.c47
-rw-r--r--stm/printf.c10
-rw-r--r--stm/pybwlan.c2
-rw-r--r--stm/servo.c9
-rw-r--r--stm/storage.c30
-rw-r--r--stm/storage.h6
-rw-r--r--stm/systick.c2
-rw-r--r--stm/systick.h2
-rw-r--r--stm/usart.c8
-rw-r--r--stm/usart.h4
-rw-r--r--stm/usb.c2
-rw-r--r--stm/usb.h2
18 files changed, 118 insertions, 114 deletions
diff --git a/stm/audio.c b/stm/audio.c
index 34adefbcd6..829bd6dfde 100644
--- a/stm/audio.c
+++ b/stm/audio.c
@@ -22,7 +22,7 @@ int sample_buf_in;
int sample_buf_out;
byte sample_buf[SAMPLE_BUF_SIZE];
-bool audio_is_full(void) {
+MP_BOOL audio_is_full(void) {
return ((sample_buf_in + 1) % SAMPLE_BUF_SIZE) == sample_buf_out;
}
diff --git a/stm/cc3k/pybcc3k.c b/stm/cc3k/pybcc3k.c
index 9b7113869d..aa83d4a277 100644
--- a/stm/cc3k/pybcc3k.c
+++ b/stm/cc3k/pybcc3k.c
@@ -165,11 +165,11 @@ void pyb_cc3000_spi_init(void) {
/*
// WLAN CS, EN and WALN IRQ Configuration
- jshSetPinStateIsManual(WLAN_CS_PIN, false);
+ jshSetPinStateIsManual(WLAN_CS_PIN, MP_FALSE);
jshPinOutput(WLAN_CS_PIN, 1); // de-assert CS
- jshSetPinStateIsManual(WLAN_EN_PIN, false);
+ jshSetPinStateIsManual(WLAN_EN_PIN, MP_FALSE);
jshPinOutput(WLAN_EN_PIN, 0); // disable WLAN
- jshSetPinStateIsManual(WLAN_IRQ_PIN, true);
+ jshSetPinStateIsManual(WLAN_IRQ_PIN, MP_TRUE);
jshPinSetState(WLAN_IRQ_PIN, JSHPINSTATE_GPIO_IN_PULLUP); // flip into read mode with pullup
*/
// configure wlan CS and EN pins
diff --git a/stm/i2c.c b/stm/i2c.c
index 9e25ff9839..6456a15793 100644
--- a/stm/i2c.c
+++ b/stm/i2c.c
@@ -20,9 +20,9 @@ typedef enum {
I2C_STATE_READ = 2,
} i2c_state_t;
-// set to true if the port has already been initialized
-bool i2c1_port_initialized = false;
-bool i2c2_port_initialized = false;
+// set to MP_TRUE if the port has already been initialized
+MP_BOOL i2c1_port_initialized = MP_FALSE;
+MP_BOOL i2c2_port_initialized = MP_FALSE;
static I2C_TypeDef * _i2c_port_addr(pyb_i2c_t i2c_port) {
if (i2c_port == PYB_I2C_1) {
@@ -37,17 +37,17 @@ static I2C_TypeDef * _i2c_port_addr(pyb_i2c_t i2c_port) {
// todo - perhaps there should be some global resource management for gpio
// this function would fail if the i2c pins have already been defined for
// use by another python object
-// as it is, this always returns true (unless i2c_port is invalid)
-static bool _i2c_init(pyb_i2c_t i2c_port) {
+// as it is, this always returns MP_TRUE (unless i2c_port is invalid)
+static MP_BOOL _i2c_init(pyb_i2c_t i2c_port) {
GPIO_InitTypeDef GPIO_InitStructure;
I2C_TypeDef *i2c = _i2c_port_addr(i2c_port);
if (i2c == NULL)
- return false;
+ return MP_FALSE;
if (i2c_port == PYB_I2C_1) {
- if (i2c1_port_initialized == true) {
- return true;
+ if (i2c1_port_initialized == MP_TRUE) {
+ return MP_TRUE;
}
RCC->APB1ENR |= RCC_APB1ENR_I2C1EN; // enable I2C1
@@ -64,12 +64,12 @@ static bool _i2c_init(pyb_i2c_t i2c_port) {
GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_I2C1);
- i2c1_port_initialized = true;
+ i2c1_port_initialized = MP_TRUE;
}
if (i2c_port == PYB_I2C_2) {
- if (i2c2_port_initialized == true) {
- return true;
+ if (i2c2_port_initialized == MP_TRUE) {
+ return MP_TRUE;
}
RCC->APB1ENR |= RCC_APB1ENR_I2C2EN; // enable I2C2
@@ -85,7 +85,7 @@ static bool _i2c_init(pyb_i2c_t i2c_port) {
GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_I2C2);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_I2C2);
- i2c2_port_initialized = true;
+ i2c2_port_initialized = MP_TRUE;
}
// get clock speeds
@@ -108,7 +108,7 @@ static bool _i2c_init(pyb_i2c_t i2c_port) {
// enable the I2C peripheral
i2c->CR1 |= I2C_CR1_PE;
- return true;
+ return MP_TRUE;
}
static uint32_t _i2c_get_sr(pyb_i2c_t i2c_port) {
@@ -121,9 +121,9 @@ static uint32_t _i2c_get_sr(pyb_i2c_t i2c_port) {
return (sr2 << 16) | sr1;
}
-static bool _i2c_restart(pyb_i2c_t i2c_port, uint8_t addr, int write) {
+static MP_BOOL _i2c_restart(pyb_i2c_t i2c_port, uint8_t addr, int write) {
I2C_TypeDef *i2c = _i2c_port_addr(i2c_port);
- if (i2c == NULL) return false;
+ if (i2c == NULL) return MP_FALSE;
// send start condition
i2c->CR1 |= I2C_CR1_START;
@@ -133,7 +133,7 @@ static bool _i2c_restart(pyb_i2c_t i2c_port, uint8_t addr, int write) {
while ((_i2c_get_sr(i2c_port) & 0x00030001) != 0x00030001) {
if (--timeout == 0) {
//printf("timeout in _i2c_restart\n");
- return false;
+ return MP_FALSE;
}
}
@@ -145,7 +145,7 @@ static bool _i2c_restart(pyb_i2c_t i2c_port, uint8_t addr, int write) {
while ((_i2c_get_sr(i2c_port) & 0x00070082) != 0x00070082) {
if (--timeout == 0) {
//printf("timeout in _i2c_restart write\n");
- return false;
+ return MP_FALSE;
}
}
} else {
@@ -156,16 +156,16 @@ static bool _i2c_restart(pyb_i2c_t i2c_port, uint8_t addr, int write) {
while ((_i2c_get_sr(i2c_port) & 0x00030002) != 0x00030002) {
if (--timeout == 0) {
//printf("timeout in _i2c_restart read\n");
- return false;
+ return MP_FALSE;
}
}
}
- return true;
+ return MP_TRUE;
}
-static bool _i2c_send_byte(pyb_i2c_t i2c_port, uint8_t data) {
+static MP_BOOL _i2c_send_byte(pyb_i2c_t i2c_port, uint8_t data) {
I2C_TypeDef *i2c = _i2c_port_addr(i2c_port);
- if (i2c == NULL) return false;
+ if (i2c == NULL) return MP_FALSE;
// send byte
i2c->DR = data;
@@ -174,10 +174,10 @@ static bool _i2c_send_byte(pyb_i2c_t i2c_port, uint8_t data) {
while ((_i2c_get_sr(i2c_port) & 0x00070084) != 0x00070084) {
if (--timeout == 0) {
//printf("timeout in _i2c_send_byte\n");
- return false;
+ return MP_FALSE;
}
}
- return true;
+ return MP_TRUE;
}
static uint8_t _i2c_read_ack(pyb_i2c_t i2c_port) {
@@ -220,18 +220,18 @@ static uint8_t _i2c_read_nack(pyb_i2c_t i2c_port) {
return data;
}
-static bool _i2c_start(pyb_i2c_t i2c_port) {
+static MP_BOOL _i2c_start(pyb_i2c_t i2c_port) {
I2C_TypeDef *i2c = _i2c_port_addr(i2c_port);
- if (i2c == NULL) return false;
+ if (i2c == NULL) return MP_FALSE;
// wait until I2C is not busy
uint32_t timeout = 1000000;
while (i2c->SR2 & I2C_SR2_BUSY) {
if (--timeout == 0) {
- return false;
+ return MP_FALSE;
}
}
- return true;
+ return MP_TRUE;
}
static void _i2c_stop(pyb_i2c_t i2c_port) {
@@ -264,7 +264,7 @@ mp_obj_t i2c_obj_start(mp_obj_t self_in) {
_i2c_stop(self->i2c_port);
self->i2c_state = I2C_STATE_IDLE;
}
- if (_i2c_start(self->i2c_port) == true)
+ if (_i2c_start(self->i2c_port) == MP_TRUE)
return mp_const_true;
return mp_const_false;
}
@@ -272,7 +272,7 @@ mp_obj_t i2c_obj_start(mp_obj_t self_in) {
mp_obj_t i2c_obj_write(mp_obj_t self_in, mp_obj_t data_in) {
pyb_i2c_obj_t *self = self_in;
if (self->i2c_state != I2C_STATE_WRITE) {
- if (_i2c_restart(self->i2c_port, self->i2c_addr, 1) == false) {
+ if (_i2c_restart(self->i2c_port, self->i2c_addr, 1) == MP_FALSE) {
_i2c_stop(self->i2c_port);
self->i2c_state = I2C_STATE_IDLE;
return mp_const_false;
@@ -280,7 +280,7 @@ mp_obj_t i2c_obj_write(mp_obj_t self_in, mp_obj_t data_in) {
self->i2c_state = I2C_STATE_WRITE;
}
uint8_t data = mp_obj_get_int(data_in);
- if (_i2c_send_byte(self->i2c_port, data) == false)
+ if (_i2c_send_byte(self->i2c_port, data) == MP_FALSE)
return mp_const_false;
return mp_const_true;
}
@@ -288,7 +288,7 @@ mp_obj_t i2c_obj_write(mp_obj_t self_in, mp_obj_t data_in) {
mp_obj_t i2c_obj_read(mp_obj_t self_in) {
pyb_i2c_obj_t *self = self_in;
if (self->i2c_state != I2C_STATE_READ) {
- if (_i2c_restart(self->i2c_port, self->i2c_addr, 0) == false) {
+ if (_i2c_restart(self->i2c_port, self->i2c_addr, 0) == MP_FALSE) {
_i2c_stop(self->i2c_port);
self->i2c_state = I2C_STATE_IDLE;
return mp_const_false;
@@ -302,7 +302,7 @@ mp_obj_t i2c_obj_read(mp_obj_t self_in) {
mp_obj_t i2c_obj_readAndStop(mp_obj_t self_in) {
pyb_i2c_obj_t *self = self_in;
if (self->i2c_state != I2C_STATE_READ) {
- if (_i2c_restart(self->i2c_port, self->i2c_addr, 0) == false) {
+ if (_i2c_restart(self->i2c_port, self->i2c_addr, 0) == MP_FALSE) {
_i2c_stop(self->i2c_port);
self->i2c_state = I2C_STATE_IDLE;
return mp_const_false;
@@ -326,18 +326,19 @@ static MP_DEFINE_CONST_FUN_OBJ_1(i2c_obj_read_obj, i2c_obj_read);
static MP_DEFINE_CONST_FUN_OBJ_1(i2c_obj_readAndStop_obj, i2c_obj_readAndStop);
static MP_DEFINE_CONST_FUN_OBJ_1(i2c_obj_stop_obj, i2c_obj_stop);
+static const mp_method_t i2c_obj_type_type_methods[] = {
+ { "start", &i2c_obj_start_obj },
+ { "write", &i2c_obj_write_obj },
+ { "read", &i2c_obj_read_obj },
+ { "readAndStop", &i2c_obj_readAndStop_obj },
+ { "stop", &i2c_obj_stop_obj },
+ { NULL, NULL },
+};
static const mp_obj_type_t i2c_obj_type = {
{ &mp_const_type },
"I2C",
.print = i2c_obj_print,
- .methods = {
- { "start", &i2c_obj_start_obj },
- { "write", &i2c_obj_write_obj },
- { "read", &i2c_obj_read_obj },
- { "readAndStop", &i2c_obj_readAndStop_obj },
- { "stop", &i2c_obj_stop_obj },
- { NULL, NULL },
- }
+ .methods = i2c_obj_type_type_methods,
};
// create the I2C object
@@ -350,7 +351,7 @@ mp_obj_t pyb_I2C(mp_obj_t i2c_id, mp_obj_t i2c_addr) {
case 1: i2c_port = PYB_I2C_2; break;
default: return mp_const_none;
}
- if (_i2c_init(i2c_port) == false) {
+ if (_i2c_init(i2c_port) == MP_FALSE) {
return mp_const_none;
}
pyb_i2c_obj_t *o = m_new_obj(pyb_i2c_obj_t);
diff --git a/stm/led.c b/stm/led.c
index 9809c21771..e89adbb78c 100644
--- a/stm/led.c
+++ b/stm/led.c
@@ -176,15 +176,16 @@ mp_obj_t led_obj_off(mp_obj_t self_in) {
static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_on_obj, led_obj_on);
static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_off_obj, led_obj_off);
+static const mp_method_t led_obj_type_methods[] = {
+ { "on", &led_obj_on_obj },
+ { "off", &led_obj_off_obj },
+ { NULL, NULL },
+};
static const mp_obj_type_t led_obj_type = {
{ &mp_const_type },
"Led",
.print = led_obj_print,
- .methods = {
- { "on", &led_obj_on_obj },
- { "off", &led_obj_off_obj },
- { NULL, NULL },
- }
+ .methods = led_obj_type_methods,
};
mp_obj_t pyb_Led(mp_obj_t led_id) {
diff --git a/stm/lexerstm.c b/stm/lexerstm.c
index 661dfb0160..6de908317b 100644
--- a/stm/lexerstm.c
+++ b/stm/lexerstm.c
@@ -21,7 +21,7 @@ void str_buf_free(mp_lexer_str_buf_t *sb) {
}
}
-mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, bool free_str, mp_lexer_str_buf_t *sb) {
+mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, MP_BOOL free_str, mp_lexer_str_buf_t *sb) {
sb->free = free_str;
sb->src_beg = str;
sb->src_cur = str;
diff --git a/stm/lexerstm.h b/stm/lexerstm.h
index 7e090898a2..99c270a718 100644
--- a/stm/lexerstm.h
+++ b/stm/lexerstm.h
@@ -1,5 +1,5 @@
typedef struct _py_lexer_str_buf_t {
- bool free; // free src_beg when done
+ MP_BOOL free; // free src_beg when done
const char *src_beg; // beginning of source
const char *src_cur; // current location in source
const char *src_end; // end (exclusive) of source
@@ -12,5 +12,5 @@ typedef struct _py_lexer_file_buf_t {
uint16_t pos;
} mp_lexer_file_buf_t;
-mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, bool free_str, mp_lexer_str_buf_t *sb);
+mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, MP_BOOL free_str, mp_lexer_str_buf_t *sb);
mp_lexer_t *mp_lexer_new_from_file(const char *filename, mp_lexer_file_buf_t *fb);
diff --git a/stm/main.c b/stm/main.c
index 07c974eff8..e1b695167c 100644
--- a/stm/main.c
+++ b/stm/main.c
@@ -359,7 +359,7 @@ int readline(vstr_t *line, const char *prompt) {
readline_hist[0] = strdup(vstr_str(line));
return 1;
} else if (c == 27) {
- escape = true;
+ escape = MP_TRUE;
} else if (c == 127) {
if (vstr_len(line) > len) {
vstr_cut_tail(line, 1);
@@ -432,12 +432,12 @@ void do_repl(void) {
}
mp_lexer_str_buf_t sb;
- mp_lexer_t *lex = mp_lexer_new_from_str_len("<stdin>", vstr_str(&line), vstr_len(&line), false, &sb);
+ mp_lexer_t *lex = mp_lexer_new_from_str_len("<stdin>", vstr_str(&line), vstr_len(&line), MP_FALSE, &sb);
mp_parse_node_t pn = mp_parse(lex, MP_PARSE_SINGLE_INPUT);
mp_lexer_free(lex);
if (pn != MP_PARSE_NODE_NULL) {
- mp_obj_t module_fun = mp_compile(pn, true);
+ mp_obj_t module_fun = mp_compile(pn, MP_TRUE);
if (module_fun != mp_const_none) {
nlr_buf_t nlr;
uint32_t start = sys_tick_counter;
@@ -461,37 +461,37 @@ void do_repl(void) {
stdout_tx_str("\r\n");
}
-bool do_file(const char *filename) {
+MP_BOOL do_file(const char *filename) {
mp_lexer_file_buf_t fb;
mp_lexer_t *lex = mp_lexer_new_from_file(filename, &fb);
if (lex == NULL) {
printf("could not open file '%s' for reading\n", filename);
- return false;
+ return MP_FALSE;
}
mp_parse_node_t pn = mp_parse(lex, MP_PARSE_FILE_INPUT);
mp_lexer_free(lex);
if (pn == MP_PARSE_NODE_NULL) {
- return false;
+ return MP_FALSE;
}
- mp_obj_t module_fun = mp_compile(pn, false);
+ mp_obj_t module_fun = mp_compile(pn, MP_FALSE);
if (module_fun == mp_const_none) {
- return false;
+ return MP_FALSE;
}
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
rt_call_function_0(module_fun);
nlr_pop();
- return true;
+ return MP_TRUE;
} else {
// uncaught exception
mp_obj_print((mp_obj_t)nlr.ret_val);
printf("\n");
- return false;
+ return MP_FALSE;
}
}
@@ -689,6 +689,12 @@ static MP_DEFINE_CONST_FUN_OBJ_1(file_obj_close_obj, file_obj_close);
// TODO gc hook to close the file if not already closed
+static const mp_method_t file_obj_type_methods[] = {
+ { "read", &file_obj_read_obj },
+ { "write", &file_obj_write_obj },
+ { "close", &file_obj_close_obj },
+ { NULL, NULL },
+};
static const mp_obj_type_t file_obj_type = {
{ &mp_const_type },
"File",
@@ -699,12 +705,7 @@ static const mp_obj_type_t file_obj_type = {
NULL, // binary_op
NULL, // getiter
NULL, // iternext
- .methods = {
- { "read", &file_obj_read_obj },
- { "write", &file_obj_write_obj },
- { "close", &file_obj_close_obj },
- {NULL, NULL},
- }
+ .methods = file_obj_type_methods,
};
mp_obj_t pyb_io_open(mp_obj_t o_filename, mp_obj_t o_mode) {
@@ -778,7 +779,7 @@ int main(void) {
//usart_init(); disabled while wi-fi is enabled
- int first_soft_reset = true;
+ int first_soft_reset = MP_TRUE;
soft_reset:
@@ -847,12 +848,12 @@ soft_reset:
lcd_print_str(" micro py board\n");
// check if user switch held (initiates reset of filesystem)
- bool reset_filesystem = false;
+ MP_BOOL reset_filesystem = MP_FALSE;
if (switch_get()) {
- reset_filesystem = true;
+ reset_filesystem = MP_TRUE;
for (int i = 0; i < 50; i++) {
if (!switch_get()) {
- reset_filesystem = false;
+ reset_filesystem = MP_FALSE;
break;
}
sys_tick_delay_ms(10);
@@ -1063,7 +1064,7 @@ soft_reset:
"f()\n";
mp_lexer_str_buf_t mp_lexer_str_buf;
- mp_lexer_t *lex = mp_lexer_new_from_str_len("<stdin>", pysrc, strlen(pysrc), false, &mp_lexer_str_buf);
+ mp_lexer_t *lex = mp_lexer_new_from_str_len("<stdin>", pysrc, strlen(pysrc), MP_FALSE, &mp_lexer_str_buf);
// nalloc=1740;6340;6836 -> 140;4600;496 bytes for lexer, parser, compiler
printf("lex; al=%u\n", m_get_total_bytes_allocated());
@@ -1074,7 +1075,7 @@ soft_reset:
printf("pars;al=%u\n", m_get_total_bytes_allocated());
sys_tick_delay_ms(1000);
//parse_node_show(pn, 0);
- mp_obj_t module_fun = mp_compile(pn, false);
+ mp_obj_t module_fun = mp_compile(pn, MP_FALSE);
printf("comp;al=%u\n", m_get_total_bytes_allocated());
sys_tick_delay_ms(1000);
@@ -1171,7 +1172,7 @@ soft_reset:
printf("PYB: soft reboot\n");
- first_soft_reset = false;
+ first_soft_reset = MP_FALSE;
goto soft_reset;
}
diff --git a/stm/printf.c b/stm/printf.c
index 8a59f8a986..7ada626bd5 100644
--- a/stm/printf.c
+++ b/stm/printf.c
@@ -152,10 +152,10 @@ int pfenv_printf(const pfenv_t *pfenv, const char *fmt, va_list args) {
}
// parse long specifiers (current not used)
- //bool long_arg = false;
+ //MP_BOOL long_arg = MP_FALSE;
if (*fmt == 'l') {
++fmt;
- //long_arg = true;
+ //long_arg = MP_TRUE;
}
if (*fmt == '\0') {
@@ -215,14 +215,14 @@ int pfenv_printf(const pfenv_t *pfenv, const char *fmt, va_list args) {
void stdout_print_strn(void *data, const char *str, unsigned int len) {
// send stdout to USART, USB CDC VCP, and LCD if nothing else
- bool any = false;
+ MP_BOOL any = MP_FALSE;
if (usart_is_enabled()) {
usart_tx_strn_cooked(str, len);
- any = true;
+ any = MP_TRUE;
}
if (usb_vcp_is_enabled()) {
usb_vcp_send_strn_cooked(str, len);
- any = true;
+ any = MP_TRUE;
}
if (!any) {
lcd_print_strn(str, len);
diff --git a/stm/pybwlan.c b/stm/pybwlan.c
index 6988f1c848..cffa016844 100644
--- a/stm/pybwlan.c
+++ b/stm/pybwlan.c
@@ -336,7 +336,7 @@ void CC3000_UsynchCallback(long lEventType, char * data, unsigned char length)
socketnum = data[0];
//PRINT_F("TCP Close wait #"); printDec(socketnum);
if (socketnum < MAX_SOCKETS)
- closed_sockets[socketnum] = true;
+ closed_sockets[socketnum] = MP_TRUE;
*/
}
}
diff --git a/stm/servo.c b/stm/servo.c
index 31190ce795..7facce7456 100644
--- a/stm/servo.c
+++ b/stm/servo.c
@@ -137,14 +137,15 @@ static mp_obj_t servo_obj_angle(mp_obj_t self_in, mp_obj_t angle) {
static MP_DEFINE_CONST_FUN_OBJ_2(servo_obj_angle_obj, servo_obj_angle);
+static const mp_method_t servo_obj_type_methods[] = {
+ { "angle", &servo_obj_angle_obj },
+ { NULL, NULL },
+};
static const mp_obj_type_t servo_obj_type = {
{ &mp_const_type },
"Servo",
.print = servo_obj_print,
- .methods = {
- { "angle", &servo_obj_angle_obj },
- { NULL, NULL },
- }
+ .methods = servo_obj_type_methods,
};
mp_obj_t pyb_Servo(mp_obj_t servo_id) {
diff --git a/stm/storage.c b/stm/storage.c
index daee4adb5e..f1ec9f6522 100644
--- a/stm/storage.c
+++ b/stm/storage.c
@@ -15,18 +15,18 @@
#define FLASH_PART1_NUM_BLOCKS (224) // 16k+16k+16k+64k=112k
#define FLASH_MEM_START_ADDR (0x08004000) // sector 1, 16k
-static bool is_initialised = false;
+static MP_BOOL is_initialised = MP_FALSE;
static uint32_t cache_flash_sector_id;
static uint32_t cache_flash_sector_start;
static uint32_t cache_flash_sector_size;
-static bool cache_dirty;
+static MP_BOOL cache_dirty;
static uint32_t sys_tick_counter_last_write;
static void cache_flush(void) {
if (cache_dirty) {
// sync the cache RAM buffer by writing it to the flash page
flash_write(cache_flash_sector_start, (const uint32_t*)CACHE_MEM_START_ADDR, cache_flash_sector_size / 4);
- cache_dirty = false;
+ cache_dirty = MP_FALSE;
// indicate a clean cache with LED off
led_state(PYB_LED_R1, 0);
}
@@ -43,7 +43,7 @@ static uint8_t *cache_get_addr_for_write(uint32_t flash_addr) {
cache_flash_sector_start = flash_sector_start;
cache_flash_sector_size = flash_sector_size;
}
- cache_dirty = true;
+ cache_dirty = MP_TRUE;
// indicate a dirty cache with LED on
led_state(PYB_LED_R1, 1);
return (uint8_t*)CACHE_MEM_START_ADDR + flash_addr - flash_sector_start;
@@ -64,8 +64,8 @@ static uint8_t *cache_get_addr_for_read(uint32_t flash_addr) {
void storage_init(void) {
if (!is_initialised) {
cache_flash_sector_id = 0;
- cache_dirty = false;
- is_initialised = true;
+ cache_dirty = MP_FALSE;
+ is_initialised = MP_TRUE;
sys_tick_counter_last_write = 0;
}
}
@@ -78,7 +78,7 @@ uint32_t storage_get_block_count(void) {
return FLASH_PART1_START_BLOCK + FLASH_PART1_NUM_BLOCKS;
}
-bool storage_needs_flush(void) {
+MP_BOOL storage_needs_flush(void) {
// wait 2 seconds after last write to flush
return cache_dirty && sys_tick_has_passed(sys_tick_counter_last_write, 2000);
}
@@ -123,7 +123,7 @@ static void build_partition(uint8_t *buf, int boot, int type, uint32_t start_blo
buf[15] = num_blocks >> 24;
}
-bool storage_read_block(uint8_t *dest, uint32_t block) {
+MP_BOOL storage_read_block(uint8_t *dest, uint32_t block) {
//printf("RD %u\n", block);
if (block == 0) {
// fake the MBR so we can decide on our own partition table
@@ -140,26 +140,26 @@ bool storage_read_block(uint8_t *dest, uint32_t block) {
dest[510] = 0x55;
dest[511] = 0xaa;
- return true;
+ return MP_TRUE;
} else if (FLASH_PART1_START_BLOCK <= block && block < FLASH_PART1_START_BLOCK + FLASH_PART1_NUM_BLOCKS) {
// non-MBR block, get data from flash memory, possibly via cache
uint32_t flash_addr = FLASH_MEM_START_ADDR + (block - FLASH_PART1_START_BLOCK) * BLOCK_SIZE;
uint8_t *src = cache_get_addr_for_read(flash_addr);
memcpy(dest, src, BLOCK_SIZE);
- return true;
+ return MP_TRUE;
} else {
// bad block number
- return false;
+ return MP_FALSE;
}
}
-bool storage_write_block(const uint8_t *src, uint32_t block) {
+MP_BOOL storage_write_block(const uint8_t *src, uint32_t block) {
//printf("WR %u\n", block);
if (block == 0) {
// can't write MBR, but pretend we did
- return true;
+ return MP_TRUE;
} else if (FLASH_PART1_START_BLOCK <= block && block < FLASH_PART1_START_BLOCK + FLASH_PART1_NUM_BLOCKS) {
// non-MBR block, copy to cache
@@ -167,10 +167,10 @@ bool storage_write_block(const uint8_t *src, uint32_t block) {
uint8_t *dest = cache_get_addr_for_write(flash_addr);
memcpy(dest, src, BLOCK_SIZE);
sys_tick_counter_last_write = sys_tick_counter;
- return true;
+ return MP_TRUE;
} else {
// bad block number
- return false;
+ return MP_FALSE;
}
}
diff --git a/stm/storage.h b/stm/storage.h
index fe37e8b27c..7bdcfc7cce 100644
--- a/stm/storage.h
+++ b/stm/storage.h
@@ -1,7 +1,7 @@
void storage_init(void);
uint32_t storage_get_block_size(void);
uint32_t storage_get_block_count(void);
-bool storage_needs_flush(void);
+MP_BOOL storage_needs_flush(void);
void storage_flush(void);
-bool storage_read_block(uint8_t *dest, uint32_t block);
-bool storage_write_block(const uint8_t *src, uint32_t block);
+MP_BOOL storage_read_block(uint8_t *dest, uint32_t block);
+MP_BOOL storage_write_block(const uint8_t *src, uint32_t block);
diff --git a/stm/systick.c b/stm/systick.c
index 40ae532793..f9def4a026 100644
--- a/stm/systick.c
+++ b/stm/systick.c
@@ -43,7 +43,7 @@ void sys_tick_wait_at_least(uint32_t stc, uint32_t delay_ms) {
}
}
-bool sys_tick_has_passed(uint32_t stc, uint32_t delay_ms) {
+MP_BOOL sys_tick_has_passed(uint32_t stc, uint32_t delay_ms) {
// stc_wait is the value of sys_tick_counter that we wait for
uint32_t stc_wait = stc + delay_ms;
if (stc_wait < stc) {
diff --git a/stm/systick.h b/stm/systick.h
index 7d2deed119..518d872c25 100644
--- a/stm/systick.h
+++ b/stm/systick.h
@@ -4,4 +4,4 @@ void sys_tick_init(void);
void SysTick_Handler(void);
void sys_tick_delay_ms(uint32_t delay_ms);
void sys_tick_wait_at_least(uint32_t stc, uint32_t delay_ms);
-bool sys_tick_has_passed(uint32_t stc, uint32_t delay_ms);
+MP_BOOL sys_tick_has_passed(uint32_t stc, uint32_t delay_ms);
diff --git a/stm/usart.c b/stm/usart.c
index 307aff1662..6e300a29e4 100644
--- a/stm/usart.c
+++ b/stm/usart.c
@@ -5,7 +5,7 @@
#include "misc.h"
#include "usart.h"
-static bool is_enabled;
+static MP_BOOL is_enabled;
// USART6 on PC6 (TX), PC7 (RX)
void usart_init(void) {
@@ -33,14 +33,14 @@ void usart_init(void) {
USART_Cmd(USART6, ENABLE);
- is_enabled = true;
+ is_enabled = MP_TRUE;
}
-bool usart_is_enabled(void) {
+MP_BOOL usart_is_enabled(void) {
return is_enabled;
}
-bool usart_rx_any(void) {
+MP_BOOL usart_rx_any(void) {
return USART_GetFlagStatus(USART6, USART_FLAG_RXNE) == SET;
}
diff --git a/stm/usart.h b/stm/usart.h
index 9d92e59f5a..ad57587ce3 100644
--- a/stm/usart.h
+++ b/stm/usart.h
@@ -1,6 +1,6 @@
void usart_init(void);
-bool usart_is_enabled(void);
-bool usart_rx_any(void);
+MP_BOOL usart_is_enabled(void);
+MP_BOOL usart_rx_any(void);
int usart_rx_char(void);
void usart_tx_char(int c);
void usart_tx_str(const char *str);
diff --git a/stm/usb.c b/stm/usb.c
index b0fbfa1941..6b553914ec 100644
--- a/stm/usb.c
+++ b/stm/usb.c
@@ -30,7 +30,7 @@ void usb_init(void) {
is_enabled = 1;
}
-bool usb_vcp_is_enabled(void) {
+MP_BOOL usb_vcp_is_enabled(void) {
return is_enabled;
}
diff --git a/stm/usb.h b/stm/usb.h
index c4b3b151fb..6f8172a3fb 100644
--- a/stm/usb.h
+++ b/stm/usb.h
@@ -1,5 +1,5 @@
void usb_init(void);
-bool usb_vcp_is_enabled(void);
+MP_BOOL usb_vcp_is_enabled(void);
int usb_vcp_rx_any(void);
char usb_vcp_rx_get(void);
void usb_vcp_send_str(const char* str);