aboutsummaryrefslogtreecommitdiff
path: root/stmhal
diff options
context:
space:
mode:
authorDamien George2014-03-26 20:15:40 +0000
committerDamien George2014-03-26 20:15:40 +0000
commitc12b2213c16ba8839981c362c4d5f133a84b374b (patch)
tree59e3de4cce2ab28a9d4f73ba70477be98fb3c353 /stmhal
parent69b3ba0df38e276b55f8f76e7f5276723e6d3abe (diff)
Change mp_method_t.name from const char * to qstr.
Addresses issue #377.
Diffstat (limited to 'stmhal')
-rw-r--r--stmhal/accel.c24
-rw-r--r--stmhal/adc.c14
-rw-r--r--stmhal/dac.c10
-rw-r--r--stmhal/exti.c10
-rw-r--r--stmhal/file.c8
-rw-r--r--stmhal/help.c18
-rw-r--r--stmhal/i2c.c8
-rw-r--r--stmhal/led.c10
-rw-r--r--stmhal/qstrdefsport.h66
-rw-r--r--stmhal/sdcard.c8
-rw-r--r--stmhal/servo.c4
-rw-r--r--stmhal/usart.c10
12 files changed, 117 insertions, 73 deletions
diff --git a/stmhal/accel.c b/stmhal/accel.c
index f79169161..15782419b 100644
--- a/stmhal/accel.c
+++ b/stmhal/accel.c
@@ -141,32 +141,32 @@ STATIC mp_obj_t pyb_accel_filtered_xyz(mp_obj_t self_in) {
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_accel_filtered_xyz_obj, pyb_accel_filtered_xyz);
-STATIC mp_obj_t pyb_accel_read_reg(mp_obj_t self_in, mp_obj_t reg) {
+STATIC mp_obj_t pyb_accel_read(mp_obj_t self_in, mp_obj_t reg) {
uint8_t data[1];
HAL_I2C_Mem_Read(&I2cHandle_X, MMA_ADDR, mp_obj_get_int(reg), I2C_MEMADD_SIZE_8BIT, data, 1, 200);
return mp_obj_new_int(data[0]);
}
-MP_DEFINE_CONST_FUN_OBJ_2(pyb_accel_read_reg_obj, pyb_accel_read_reg);
+MP_DEFINE_CONST_FUN_OBJ_2(pyb_accel_read_obj, pyb_accel_read);
-STATIC mp_obj_t pyb_accel_write_reg(mp_obj_t self_in, mp_obj_t reg, mp_obj_t val) {
+STATIC mp_obj_t pyb_accel_write(mp_obj_t self_in, mp_obj_t reg, mp_obj_t val) {
uint8_t data[1];
data[0] = mp_obj_get_int(val);
HAL_I2C_Mem_Write(&I2cHandle_X, MMA_ADDR, mp_obj_get_int(reg), I2C_MEMADD_SIZE_8BIT, data, 1, 200);
return mp_const_none;
}
-MP_DEFINE_CONST_FUN_OBJ_3(pyb_accel_write_reg_obj, pyb_accel_write_reg);
+MP_DEFINE_CONST_FUN_OBJ_3(pyb_accel_write_obj, pyb_accel_write);
STATIC const mp_method_t pyb_accel_methods[] = {
- { "x", &pyb_accel_x_obj },
- { "y", &pyb_accel_y_obj },
- { "z", &pyb_accel_z_obj },
- { "tilt", &pyb_accel_tilt_obj },
- { "filtered_xyz", &pyb_accel_filtered_xyz_obj },
- { "read_reg", &pyb_accel_read_reg_obj },
- { "write_reg", &pyb_accel_write_reg_obj },
- { NULL, NULL },
+ { MP_QSTR_x, &pyb_accel_x_obj },
+ { MP_QSTR_y, &pyb_accel_y_obj },
+ { MP_QSTR_z, &pyb_accel_z_obj },
+ { MP_QSTR_tilt, &pyb_accel_tilt_obj },
+ { MP_QSTR_filtered_xyz, &pyb_accel_filtered_xyz_obj },
+ { MP_QSTR_read, &pyb_accel_read_obj },
+ { MP_QSTR_write, &pyb_accel_write_obj },
+ { MP_QSTR_NULL, NULL },
};
const mp_obj_type_t pyb_accel_type = {
diff --git a/stmhal/adc.c b/stmhal/adc.c
index e357a0030..7d0d3da99 100644
--- a/stmhal/adc.c
+++ b/stmhal/adc.c
@@ -164,8 +164,8 @@ STATIC mp_obj_t adc_read(mp_obj_t self_in) {
STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_read_obj, adc_read);
STATIC const mp_method_t adc_methods[] = {
- { "read", &adc_read_obj},
- { NULL, NULL },
+ { MP_QSTR_read, &adc_read_obj},
+ { MP_QSTR_NULL, NULL },
};
const mp_obj_type_t pyb_adc_type = {
@@ -321,11 +321,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_all_read_core_vbat_obj, adc_all_read_core_v
STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_all_read_core_vref_obj, adc_all_read_core_vref);
STATIC const mp_method_t adc_all_methods[] = {
- { "read_channel", &adc_all_read_channel_obj},
- { "read_core_temp", &adc_all_read_core_temp_obj},
- { "read_core_vbat", &adc_all_read_core_vbat_obj},
- { "read_core_vref", &adc_all_read_core_vref_obj},
- { NULL, NULL },
+ { MP_QSTR_read_channel, &adc_all_read_channel_obj},
+ { MP_QSTR_read_core_temp, &adc_all_read_core_temp_obj},
+ { MP_QSTR_read_core_vbat, &adc_all_read_core_vbat_obj},
+ { MP_QSTR_read_core_vref, &adc_all_read_core_vref_obj},
+ { MP_QSTR_NULL, NULL },
};
STATIC const mp_obj_type_t adc_all_type = {
diff --git a/stmhal/dac.c b/stmhal/dac.c
index 3814039cc..bc86e07bd 100644
--- a/stmhal/dac.c
+++ b/stmhal/dac.c
@@ -261,14 +261,14 @@ mp_obj_t pyb_dac_dma(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) {
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_dac_dma_obj, 3, pyb_dac_dma);
STATIC const mp_method_t pyb_dac_methods[] = {
- { "noise", &pyb_dac_noise_obj },
- { "triangle", &pyb_dac_triangle_obj },
- { "write", &pyb_dac_write_obj },
- { "dma", &pyb_dac_dma_obj },
+ { MP_QSTR_noise, &pyb_dac_noise_obj },
+ { MP_QSTR_triangle, &pyb_dac_triangle_obj },
+ { MP_QSTR_write, &pyb_dac_write_obj },
+ { MP_QSTR_dma, &pyb_dac_dma_obj },
// TODO add function that does double buffering:
// dma2(freq, buf1, buf2, callback)
// where callback is called when the buffer has been drained
- { NULL, NULL },
+ { MP_QSTR_NULL, NULL },
};
const mp_obj_type_t pyb_dac_type = {
diff --git a/stmhal/exti.c b/stmhal/exti.c
index 8aaa99d42..41f8e378a 100644
--- a/stmhal/exti.c
+++ b/stmhal/exti.c
@@ -229,11 +229,11 @@ static MP_DEFINE_CONST_FUN_OBJ_1(exti_obj_disable_obj, exti_obj_disable);
static MP_DEFINE_CONST_FUN_OBJ_1(exti_obj_swint_obj, exti_obj_swint);
static const mp_method_t exti_methods[] = {
- { "line", &exti_obj_line_obj },
- { "enable", &exti_obj_enable_obj },
- { "disable", &exti_obj_disable_obj },
- { "swint", &exti_obj_swint_obj },
- { NULL, NULL },
+ { MP_QSTR_line, &exti_obj_line_obj },
+ { MP_QSTR_enable, &exti_obj_enable_obj },
+ { MP_QSTR_disable, &exti_obj_disable_obj },
+ { MP_QSTR_swint, &exti_obj_swint_obj },
+ { MP_QSTR_NULL, NULL },
};
static mp_obj_t exti_regs(void) {
diff --git a/stmhal/file.c b/stmhal/file.c
index 83bb6013f..210d26803 100644
--- a/stmhal/file.c
+++ b/stmhal/file.c
@@ -52,10 +52,10 @@ 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_methods[] = {
- { "read", &file_obj_read_obj },
- { "write", &file_obj_write_obj },
- { "close", &file_obj_close_obj },
- {NULL, NULL},
+ { MP_QSTR_read, &file_obj_read_obj },
+ { MP_QSTR_write, &file_obj_write_obj },
+ { MP_QSTR_close, &file_obj_close_obj },
+ { MP_QSTR_NULL, NULL },
};
static const mp_obj_type_t file_obj_type = {
diff --git a/stmhal/help.c b/stmhal/help.c
index 9efe37452..a1c81c824 100644
--- a/stmhal/help.c
+++ b/stmhal/help.c
@@ -38,14 +38,10 @@ STATIC const char *help_text =
" CTRL-D -- on a blank line, do a soft reset of the board\n"
;
-STATIC void pyb_help_print_info_about_object(mp_obj_t name_o, const char *name_str, mp_obj_t value) {
- if (name_o != MP_OBJ_NULL) {
- printf(" ");
- mp_obj_print(name_o, PRINT_STR);
- printf(" -- ");
- } else {
- printf(" %s -- ", name_str);
- }
+STATIC void pyb_help_print_info_about_object(mp_obj_t name_o, mp_obj_t value) {
+ printf(" ");
+ mp_obj_print(name_o, PRINT_STR);
+ printf(" -- ");
mp_obj_print(value, PRINT_STR);
printf("\n");
}
@@ -72,14 +68,14 @@ STATIC mp_obj_t pyb_help(uint n_args, const mp_obj_t *args) {
if (map != NULL) {
for (uint i = 0; i < map->alloc; i++) {
if (map->table[i].key != MP_OBJ_NULL) {
- pyb_help_print_info_about_object(map->table[i].key, NULL, map->table[i].value);
+ pyb_help_print_info_about_object(map->table[i].key, map->table[i].value);
}
}
}
if (type->methods != NULL) {
- for (const mp_method_t *meth = type->methods; meth->name != NULL; meth++) {
- pyb_help_print_info_about_object(MP_OBJ_NULL, meth->name, (mp_obj_t)meth->fun);
+ for (const mp_method_t *meth = type->methods; meth->name != MP_QSTR_NULL; meth++) {
+ pyb_help_print_info_about_object(MP_OBJ_NEW_QSTR(meth->name), (mp_obj_t)meth->fun);
}
}
}
diff --git a/stmhal/i2c.c b/stmhal/i2c.c
index b8608ad3b..91cb17b33 100644
--- a/stmhal/i2c.c
+++ b/stmhal/i2c.c
@@ -170,10 +170,10 @@ STATIC mp_obj_t pyb_i2c_mem_write(uint n_args, const mp_obj_t *args) {
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_i2c_mem_write_obj, 4, 4, pyb_i2c_mem_write);
STATIC const mp_method_t pyb_i2c_methods[] = {
- { "is_ready", &pyb_i2c_is_ready_obj },
- { "mem_read", &pyb_i2c_mem_read_obj },
- { "mem_write", &pyb_i2c_mem_write_obj },
- { NULL, NULL },
+ { MP_QSTR_is_ready, &pyb_i2c_is_ready_obj },
+ { MP_QSTR_mem_read, &pyb_i2c_mem_read_obj },
+ { MP_QSTR_mem_write, &pyb_i2c_mem_write_obj },
+ { MP_QSTR_NULL, NULL },
};
const mp_obj_type_t pyb_i2c_type = {
diff --git a/stmhal/led.c b/stmhal/led.c
index 688daefc8..989ce3897 100644
--- a/stmhal/led.c
+++ b/stmhal/led.c
@@ -257,11 +257,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(led_obj_toggle_obj, led_obj_toggle);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(led_obj_intensity_obj, 1, 2, led_obj_intensity);
STATIC const mp_method_t led_methods[] = {
- { "on", &led_obj_on_obj },
- { "off", &led_obj_off_obj },
- { "toggle", &led_obj_toggle_obj },
- { "intensity", &led_obj_intensity_obj },
- { NULL, NULL },
+ { MP_QSTR_on, &led_obj_on_obj },
+ { MP_QSTR_off, &led_obj_off_obj },
+ { MP_QSTR_toggle, &led_obj_toggle_obj },
+ { MP_QSTR_intensity, &led_obj_intensity_obj },
+ { MP_QSTR_NULL, NULL },
};
const mp_obj_type_t pyb_led_type = {
diff --git a/stmhal/qstrdefsport.h b/stmhal/qstrdefsport.h
index 4036dcd25..c8e678333 100644
--- a/stmhal/qstrdefsport.h
+++ b/stmhal/qstrdefsport.h
@@ -4,6 +4,8 @@ Q(help)
Q(pyb)
Q(info)
Q(sd_test)
+Q(present)
+Q(power)
Q(stop)
Q(standby)
Q(source_dir)
@@ -17,23 +19,17 @@ Q(switch)
Q(SW)
Q(servo)
Q(pwm)
-Q(Accel)
+Q(read)
+Q(write)
Q(hid)
Q(time)
Q(rng)
-Q(Led)
Q(LCD)
-Q(Servo)
Q(SD)
Q(SDcard)
-Q(I2C)
Q(gpio)
Q(gpio_in)
Q(gpio_out)
-Q(Usart)
-Q(ADC)
-Q(ADC_all)
-Q(DAC)
Q(open)
Q(File)
// Entries for sys.path
@@ -44,7 +40,6 @@ Q(Pin)
Q(PinMap)
Q(PinAF)
Q(PinNamed)
-Q(Exti)
Q(ExtiMeta)
Q(rtc_info)
Q(millis)
@@ -54,6 +49,59 @@ Q(PULL_DOWN)
Q(PUSH_PULL)
Q(OPEN_DRAIN)
+// for Led object
+Q(Led)
+Q(on)
+Q(off)
+Q(toggle)
+Q(intensity)
+
+// for Usart object
+Q(Usart)
+Q(status)
+Q(recv_chr)
+Q(send_chr)
+Q(send)
+
+// for exti object
+Q(Exti)
+Q(line)
+Q(enable)
+Q(disable)
+Q(swint)
+
+// for I2C object
+Q(I2C)
+Q(is_ready)
+Q(mem_read)
+Q(mem_write)
+
+// for Accel object
+Q(Accel)
+Q(x)
+Q(y)
+Q(z)
+Q(tilt)
+Q(filtered_xyz)
+
+// for ADC object
+Q(ADC)
+Q(ADC_all)
+Q(read_channel)
+Q(read_core_temp)
+Q(read_core_vbat)
+Q(read_core_vref)
+
+// for DAC object
+Q(DAC)
+Q(noise)
+Q(triangle)
+Q(dma)
+
+// for Servo object
+Q(Servo)
+Q(angle)
+
// for os module
Q(os)
Q(/)
diff --git a/stmhal/sdcard.c b/stmhal/sdcard.c
index 20a481849..5392b0273 100644
--- a/stmhal/sdcard.c
+++ b/stmhal/sdcard.c
@@ -233,10 +233,10 @@ static mp_obj_t sd_read(mp_obj_t self, mp_obj_t block_num) {
static MP_DEFINE_CONST_FUN_OBJ_2(sd_read_obj, sd_read);
static const mp_method_t sdcard_methods[] = {
- { "present", &sd_present_obj },
- { "power", &sd_power_obj },
- { "read", &sd_read_obj },
- { NULL, NULL },
+ { MP_QSTR_present, &sd_present_obj },
+ { MP_QSTR_power, &sd_power_obj },
+ { MP_QSTR_read, &sd_read_obj },
+ { MP_QSTR_NULL, NULL },
};
static const mp_obj_type_t sdcard_type = {
diff --git a/stmhal/servo.c b/stmhal/servo.c
index 81b290bf5..17722dc6c 100644
--- a/stmhal/servo.c
+++ b/stmhal/servo.c
@@ -206,8 +206,8 @@ STATIC mp_obj_t pyb_servo_angle(uint n_args, const mp_obj_t *args) {
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_servo_angle_obj, 1, 3, pyb_servo_angle);
STATIC const mp_method_t pyb_servo_methods[] = {
- { "angle", &pyb_servo_angle_obj },
- { NULL, NULL },
+ { MP_QSTR_angle, &pyb_servo_angle_obj },
+ { MP_QSTR_NULL, NULL },
};
const mp_obj_type_t pyb_servo_type = {
diff --git a/stmhal/usart.c b/stmhal/usart.c
index 31308c22a..d3a54f9d8 100644
--- a/stmhal/usart.c
+++ b/stmhal/usart.c
@@ -210,11 +210,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(usart_obj_tx_char_obj, usart_obj_tx_char);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(usart_obj_tx_str_obj, usart_obj_tx_str);
STATIC const mp_method_t usart_methods[] = {
- { "status", &usart_obj_status_obj },
- { "recv_chr", &usart_obj_rx_char_obj },
- { "send_chr", &usart_obj_tx_char_obj },
- { "send", &usart_obj_tx_str_obj },
- { NULL, NULL },
+ { MP_QSTR_status, &usart_obj_status_obj },
+ { MP_QSTR_recv_chr, &usart_obj_rx_char_obj },
+ { MP_QSTR_send_chr, &usart_obj_tx_char_obj },
+ { MP_QSTR_send, &usart_obj_tx_str_obj },
+ { MP_QSTR_NULL, NULL },
};
const mp_obj_type_t pyb_usart_type = {