Change old use of module creation to new proper use.

genexit-inst
Damien George 2014-01-03 00:10:22 +00:00
parent 2870862601
commit aae7847508
6 changed files with 17 additions and 11 deletions

View File

@ -77,9 +77,3 @@ mp_obj_t mp_obj_new_class(mp_map_t *class_locals) {
o->locals = class_locals;
return o;
}
// temporary way of making C modules
// hack: use class to mimic a module
mp_obj_t mp_module_new(void) {
return mp_obj_new_class(mp_map_new(MP_MAP_QSTR, 0));
}

View File

@ -1,4 +1,5 @@
STMSRC=lib
#STMOTGSRC=lib-otg
FATFSSRC=fatfs
CC3KSRC=cc3k
PYSRC=../py
@ -10,6 +11,7 @@ CC = arm-none-eabi-gcc
LD = arm-none-eabi-ld
CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mabi=aapcs-linux -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fsingle-precision-constant -Wdouble-promotion -DSTM32F40XX -DHSE_VALUE=8000000
CFLAGS = -I. -I$(PYSRC) -I$(FATFSSRC) -I$(STMSRC) -Wall -ansi -std=gnu99 -Os -DNDEBUG $(CFLAGS_CORTEX_M4)
#CFLAGS += -I$(STMOTGSRC) -DUSE_HOST_MODE -DUSE_OTG_MODE
LDFLAGS = --nostdlib -T stm32f405.ld
SRC_C = \
@ -122,6 +124,11 @@ SRC_STM = \
stm324x7i_eval.c \
stm324x7i_eval_sdio_sd.c \
#SRC_STM_OTG = \
# usb_hcd.c \
# usb_hcd_int.c \
# usb_otg.c \
SRC_CC3K = \
cc3000_common.c \
evnt_handler.c \
@ -135,6 +142,7 @@ SRC_CC3K = \
pybcc3k.c \
OBJ = $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(SRC_S:.s=.o) $(PY_O) $(SRC_FATFS:.c=.o) $(SRC_STM:.c=.o) $(SRC_CC3K:.c=.o))
#OBJ += $(addprefix $(BUILD)/, $(SRC_STM_OTG:.c=.o))
all: $(BUILD) $(BUILD)/flash.dfu
@ -166,6 +174,9 @@ $(BUILD)/%.o: $(FATFSSRC)/%.c
$(BUILD)/%.o: $(STMSRC)/%.c
$(CC) $(CFLAGS) -c -o $@ $<
#$(BUILD)/%.o: $(STMOTGSRC)/%.c
# $(CC) $(CFLAGS) -c -o $@ $<
$(BUILD)/%.o: $(CC3KSRC)/%.c
$(CC) $(CFLAGS) -c -o $@ $<

View File

@ -91,7 +91,7 @@ void audio_init(void) {
// enable interrupt
// Python interface
mp_obj_t m = mp_module_new();
mp_obj_t m = mp_obj_new_module(qstr_from_str_static("audio"));
rt_store_attr(m, qstr_from_str_static("dac"), rt_make_function_1(pyb_audio_dac));
rt_store_attr(m, qstr_from_str_static("is_full"), rt_make_function_0(pyb_audio_is_full));
rt_store_attr(m, qstr_from_str_static("fill"), rt_make_function_1(pyb_audio_fill));

View File

@ -220,7 +220,7 @@ void lcd_init(void) {
lcd_next_line = 0;
// Python interface
mp_obj_t m = mp_module_new();
mp_obj_t m = mp_obj_new_module(qstr_from_str_static("lcd"));
rt_store_attr(m, qstr_from_str_static("lcd8"), rt_make_function_2(lcd_draw_pixel_8));
rt_store_attr(m, qstr_from_str_static("clear"), rt_make_function_0(lcd_pix_clear));
rt_store_attr(m, qstr_from_str_static("get"), rt_make_function_2(lcd_pix_get));

View File

@ -20,6 +20,7 @@
#include "parse.h"
#include "compile.h"
#include "obj.h"
#include "map.h"
#include "runtime.h"
#include "cc3k/ccspi.h"
@ -74,7 +75,7 @@ mp_obj_t pyb_wlan_get_ip(void) {
return mp_const_none;
}
mp_obj_t data = mp_module_new(); // TODO should really be a class
mp_obj_t data = mp_obj_new_class(mp_map_new(MP_MAP_QSTR, 0)); // TODO should this be an instance of a class?
decode_addr_and_store(data, qstr_from_str_static("ip"), &ipconfig.aucIP[0], 4);
decode_addr_and_store(data, qstr_from_str_static("subnet"), &ipconfig.aucSubnetMask[0], 4);
decode_addr_and_store(data, qstr_from_str_static("gateway"), &ipconfig.aucDefaultGateway[0], 4);
@ -345,7 +346,7 @@ void pyb_wlan_init(void) {
SpiInit();
wlan_init(CC3000_UsynchCallback, sendWLFWPatch, sendDriverPatch, sendBootLoaderPatch, ReadWlanInterruptPin, WlanInterruptEnable, WlanInterruptDisable, WriteWlanPin);
mp_obj_t m = mp_module_new();
mp_obj_t m = mp_obj_new_module(qstr_from_str_static("wlan"));
rt_store_attr(m, qstr_from_str_static("connect"), rt_make_function_var(0, pyb_wlan_connect));
rt_store_attr(m, qstr_from_str_static("disconnect"), rt_make_function_0(pyb_wlan_disconnect));
rt_store_attr(m, qstr_from_str_static("ip"), rt_make_function_0(pyb_wlan_get_ip));

View File

@ -72,7 +72,7 @@ void timer_init(void) {
TIM_Cmd(TIM6, ENABLE);
// Python interface
mp_obj_t m = mp_module_new();
mp_obj_t m = mp_obj_new_module(qstr_from_str_static("timer"));
rt_store_attr(m, qstr_from_str_static("callback"), rt_make_function_1(timer_py_set_callback));
rt_store_attr(m, qstr_from_str_static("period"), rt_make_function_1(timer_py_set_period));
rt_store_attr(m, qstr_from_str_static("prescaler"), rt_make_function_1(timer_py_set_prescaler));