summaryrefslogtreecommitdiff
path: root/stm
diff options
context:
space:
mode:
Diffstat (limited to 'stm')
-rw-r--r--stm/lcd.c4
-rw-r--r--stm/main.c39
-rw-r--r--stm/string0.c2
-rw-r--r--stm/usart.c11
4 files changed, 35 insertions, 21 deletions
diff --git a/stm/lcd.c b/stm/lcd.c
index 56f0ffe64..0567b4333 100644
--- a/stm/lcd.c
+++ b/stm/lcd.c
@@ -165,7 +165,9 @@ mp_obj_t lcd_pix_show(void) {
}
mp_obj_t lcd_print(mp_obj_t text) {
- lcd_print_str(qstr_str(mp_obj_get_qstr(text)));
+ uint len;
+ const byte *data = mp_obj_str_get_data(text, &len);
+ lcd_print_strn((const char*)data, len);
return mp_const_none;
}
diff --git a/stm/main.c b/stm/main.c
index 990450202..8d2c2d6b3 100644
--- a/stm/main.c
+++ b/stm/main.c
@@ -69,16 +69,20 @@ void __fatal_error(const char *msg) {
}
}
-static qstr pyb_config_source_dir = 0;
-static qstr pyb_config_main = 0;
+static mp_obj_t pyb_config_source_dir = MP_OBJ_NULL;
+static mp_obj_t pyb_config_main = MP_OBJ_NULL;
mp_obj_t pyb_source_dir(mp_obj_t source_dir) {
- pyb_config_source_dir = mp_obj_get_qstr(source_dir);
+ if (MP_OBJ_IS_STR(source_dir)) {
+ pyb_config_source_dir = source_dir;
+ }
return mp_const_none;
}
mp_obj_t pyb_main(mp_obj_t main) {
- pyb_config_main = mp_obj_get_qstr(main);
+ if (MP_OBJ_IS_STR(main)) {
+ pyb_config_main = main;
+ }
return mp_const_none;
}
@@ -482,7 +486,7 @@ mp_obj_t pyb_gc(void) {
mp_obj_t pyb_gpio(uint n_args, mp_obj_t *args) {
//assert(1 <= n_args && n_args <= 2);
- const char *pin_name = qstr_str(mp_obj_get_qstr(args[0]));
+ const char *pin_name = mp_obj_str_get_str(args[0]);
GPIO_TypeDef *port;
switch (pin_name[0]) {
case 'A': case 'a': port = GPIOA; break;
@@ -630,21 +634,22 @@ void file_obj_print(void (*print)(void *env, const char *fmt, ...), void *env, m
mp_obj_t file_obj_read(mp_obj_t self_in, mp_obj_t arg) {
pyb_file_obj_t *self = self_in;
int n = mp_obj_get_int(arg);
- char *buf = m_new(char, n);
+ byte *buf = m_new(byte, n);
UINT n_out;
f_read(&self->fp, buf, n, &n_out);
- return mp_obj_new_str(qstr_from_strn_take(buf, n, n_out));
+ return mp_obj_new_str(buf, n_out, false);
}
mp_obj_t file_obj_write(mp_obj_t self_in, mp_obj_t arg) {
pyb_file_obj_t *self = self_in;
- const char *s = qstr_str(mp_obj_get_qstr(arg));
+ uint l;
+ const byte *s = mp_obj_str_get_data(arg, &l);
UINT n_out;
- FRESULT res = f_write(&self->fp, s, strlen(s), &n_out);
+ FRESULT res = f_write(&self->fp, s, l, &n_out);
if (res != FR_OK) {
printf("File error: could not write to file; error code %d\n", res);
- } else if (n_out != strlen(s)) {
- printf("File error: could not write all data to file; wrote %d / %d bytes\n", n_out, strlen(s));
+ } else if (n_out != l) {
+ printf("File error: could not write all data to file; wrote %d / %d bytes\n", n_out, l);
}
return mp_const_none;
}
@@ -676,8 +681,8 @@ static const mp_obj_type_t file_obj_type = {
};
mp_obj_t pyb_io_open(mp_obj_t o_filename, mp_obj_t o_mode) {
- const char *filename = qstr_str(mp_obj_get_qstr(o_filename));
- const char *mode = qstr_str(mp_obj_get_qstr(o_mode));
+ const char *filename = mp_obj_str_get_str(o_filename);
+ const char *mode = mp_obj_str_get_str(o_mode);
pyb_file_obj_t *self = m_new_obj(pyb_file_obj_t);
self->base.type = &file_obj_type;
if (mode[0] == 'r') {
@@ -931,16 +936,16 @@ soft_reset:
{
vstr_t *vstr = vstr_new();
vstr_add_str(vstr, "0:/");
- if (pyb_config_source_dir == 0) {
+ if (pyb_config_source_dir == MP_OBJ_NULL) {
vstr_add_str(vstr, "src");
} else {
- vstr_add_str(vstr, qstr_str(pyb_config_source_dir));
+ vstr_add_str(vstr, mp_obj_str_get_str(pyb_config_source_dir));
}
vstr_add_char(vstr, '/');
- if (pyb_config_main == 0) {
+ if (pyb_config_main == MP_OBJ_NULL) {
vstr_add_str(vstr, "main.py");
} else {
- vstr_add_str(vstr, qstr_str(pyb_config_main));
+ vstr_add_str(vstr, mp_obj_str_get_str(pyb_config_main));
}
if (!do_file(vstr_str(vstr))) {
flash_error(3);
diff --git a/stm/string0.c b/stm/string0.c
index d67c5f2b1..4899e7b0f 100644
--- a/stm/string0.c
+++ b/stm/string0.c
@@ -34,7 +34,7 @@ void *memset(void *s, int c, size_t n) {
return s;
}
-int strlen(const char *str) {
+size_t strlen(const char *str) {
int len = 0;
for (const char *s = str; *s; s++) {
len += 1;
diff --git a/stm/usart.c b/stm/usart.c
index c687cff05..17ff146d5 100644
--- a/stm/usart.c
+++ b/stm/usart.c
@@ -151,6 +151,12 @@ void usart_tx_str(pyb_usart_t usart_id, const char *str) {
}
}
+void usart_tx_bytes(pyb_usart_t usart_id, const byte *data, uint len) {
+ for (; len > 0; data++, len--) {
+ usart_tx_char(usart_id, *data);
+ }
+}
+
void usart_tx_strn_cooked(pyb_usart_t usart_id, const char *str, int len) {
for (const char *top = str + len; str < top; str++) {
if (*str == '\n') {
@@ -201,8 +207,9 @@ static mp_obj_t usart_obj_tx_str(mp_obj_t self_in, mp_obj_t s) {
pyb_usart_obj_t *self = self_in;
if (self->is_enabled) {
if (MP_OBJ_IS_TYPE(s, &str_type)) {
- const char *str = qstr_str(mp_obj_get_qstr(s));
- usart_tx_str(self->usart_id, str);
+ uint len;
+ const byte *data = mp_obj_str_get_data(s, &len);
+ usart_tx_bytes(self->usart_id, data, len);
}
}
return mp_const_none;