diff --git a/src/Makefile b/src/Makefile index 1a01b3fd4..3b636ccb9 100755 --- a/src/Makefile +++ b/src/Makefile @@ -33,9 +33,9 @@ CFLAGS += -O2 -ggdb3 -DNDEBUG endif # Compiler Flags -CFLAGS += -std=gnu99 -Wall -mlittle-endian -mthumb -nostartfiles -mabi=aapcs-linux +CFLAGS += -std=gnu99 -Wall -mlittle-endian -mthumb -nostartfiles -mabi=aapcs-linux -fdata-sections -ffunction-sections CFLAGS += -fsingle-precision-constant -Wdouble-promotion -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -CFLAGS += -DARM_MATH_CM4 -D__FPU_PRESENT=1 -D__FPU_USED=1 -DUSE_USB_FS -DUSE_DEVICE_MODE -DUSE_USB_OTG_ID=0 -DSTM32F407xx -DHSE_VALUE=12000000 +CFLAGS += -DARM_MATH_CM4 -D__FPU_PRESENT=1 -D__FPU_PRESENT -D__FPU_USED=1 -DUSE_USB_FS -DUSE_DEVICE_MODE -DUSE_USB_OTG_ID=0 -DSTM32F407xx -DHSE_VALUE=12000000 CFLAGS += -I. -Iinclude CFLAGS += -I$(TOP_DIR)/$(CMSIS_DIR)/include/ @@ -58,7 +58,7 @@ CFLAGS += -I$(TOP_DIR)/$(OMV_DIR)/img/ # Linker Flags -LDFLAGS = -mcpu=cortex-m4 -mabi=aapcs-linux -mthumb -mlittle-endian -mfloat-abi=hard -mfpu=fpv4-sp-d16 -nostdlib -Wl,-T$(OMV_DIR)/stm32f407.ld +LDFLAGS = -mcpu=cortex-m4 -mabi=aapcs-linux -mthumb -mlittle-endian -mfloat-abi=hard -mfpu=fpv4-sp-d16 -nostdlib -Wl,-T$(OMV_DIR)/stm32f407.ld -Wl,--gc-sections # Sources #SRC_C = $(addprefix $(CMSIS_DIR)/src/st/,\ @@ -67,6 +67,16 @@ LDFLAGS = -mcpu=cortex-m4 -mabi=aapcs-linux -mthumb -mlittle-endian -mfloat-abi= OBJ += $(wildcard $(BUILD)/$(CMSIS_DIR)/src/st/*.o) +OBJ += $(wildcard $(BUILD)/$(CMSIS_DIR)/src/dsp/CommonTables/*.o) +#OBJ += $(wildcard $(BUILD)/$(CMSIS_DIR)/src/dsp/ComplexMathFunctions/*.o) +#OBJ += $(wildcard $(BUILD)/$(CMSIS_DIR)/src/dsp/ControllerFunctions/*.o) +OBJ += $(wildcard $(BUILD)/$(CMSIS_DIR)/src/dsp/FastMathFunctions/*.o) +#OBJ += $(wildcard $(BUILD)/$(CMSIS_DIR)/src/dsp/FilteringFunctions/*.o) +OBJ += $(wildcard $(BUILD)/$(CMSIS_DIR)/src/dsp/MatrixFunctions/*.o) +#OBJ += $(wildcard $(BUILD)/$(CMSIS_DIR)/src/dsp/StatisticsFunctions/*.o) +#OBJ += $(wildcard $(BUILD)/$(CMSIS_DIR)/src/dsp/SupportFunctions/*.o) +#OBJ += $(wildcard $(BUILD)/$(CMSIS_DIR)/src/dsp/TransformFunctions/*.o) + OBJ += $(wildcard $(BUILD)/$(STHAL_DIR)/src/*.o) OBJ += $(wildcard $(BUILD)/$(FATFS_DIR)/src/*.o) OBJ += $(wildcard $(BUILD)/$(FATFS_DIR)/src/option/*.o) @@ -101,16 +111,12 @@ OBJ += $(addprefix $(BUILD)/$(MICROPY_DIR)/,\ math.o \ mathsincos.o \ rtc.o \ - rng.o \ pin.o \ pin_named_pins.o \ timer.o \ - i2c.o \ - spi.o \ servo.o\ extint.o \ adc.o \ - modos.o \ modstm.o \ modtime.o \ pins_$(TARGET).o \ @@ -126,20 +132,43 @@ OBJ += $(addprefix $(BUILD)/$(MICROPY_DIR)/usbdev/,\ class/cdc_msc_hid/src/usbd_msc_data.o \ ) -OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/,\ - main.o \ - systick.o\ - usbdbg.o\ - sccb.o\ - ov9650.o\ - ov2640.o\ - sensor.o\ - led.o \ +OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/, \ + main.o \ + xalloc.o \ + array.o \ + usbdbg.o \ + systick.o \ + sccb.o \ + ov9650.o \ + ov2640.o \ + sensor.o \ + led.o \ + rng.o \ ) -OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/py/,\ - py_led.o \ - py_sensor.o \ +OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/img/,\ + blob.o \ + fmath.o \ + haar.o \ + imlib.o \ + integral.o \ + kmeans.o \ + lab.o \ + median.o \ + point.o \ + ppm.o \ + rectangle.o \ + surf.o \ + template.o \ + ) + +OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/py/, \ + py_led.o \ + py_sensor.o \ + py_image.o \ + py_file.o \ + py_time.o \ + py_clock.o \ ) ################################################### diff --git a/src/cmsis/Makefile b/src/cmsis/Makefile index 00e6d8411..809c57711 100644 --- a/src/cmsis/Makefile +++ b/src/cmsis/Makefile @@ -1,16 +1,17 @@ # Sources -SRCS = src/st/startup_stm32f407xx.s -#SRCS += $(wildcard src/CommonTables/*.c) -#SRCS += $(wildcard src/ComplexMathFunctions/*.c) -#SRCS += $(wildcard src/ControllerFunctions/*.c) -#SRCS += $(wildcard src/FastMathFunctions/*.c) -#SRCS += $(wildcard src/FilteringFunctions/*.c) -#SRCS += $(wildcard src/MatrixFunctions/*.c) -#SRCS += $(wildcard src/StatisticsFunctions/*.c) -#SRCS += $(wildcard src/SupportFunctions/*.c) -#SRCS += $(wildcard src/TransformFunctions/*.c) +SRC_S = src/st/startup_stm32f407xx.s +SRC_C += $(wildcard src/dsp/CommonTables/*.c) +#SRC_C += $(wildcard src/dsp/ComplexMathFunctions/*.c) +#SRC_C += $(wildcard src/dsp/ControllerFunctions/*.c) +SRC_C += $(wildcard src/dsp/FastMathFunctions/*.c) +#SRC_C += $(wildcard src/dsp/FilteringFunctions/*.c) +SRC_C += $(wildcard src/dsp/MatrixFunctions/*.c) +#SRC_C += $(wildcard src/dsp/StatisticsFunctions/*.c) +#SRC_C += $(wildcard src/dsp/SupportFunctions/*.c) +#SRC_C += $(wildcard src/dsp/TransformFunctions/*.c) -OBJS = $(addprefix $(BUILD)/, $(SRCS:.s=.o)) +OBJS = $(addprefix $(BUILD)/, $(SRC_S:.s=.o)) +OBJS += $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) OBJ_DIRS = $(sort $(dir $(OBJS))) all: | $(OBJ_DIRS) $(OBJS) diff --git a/src/omv/Makefile b/src/omv/Makefile index ed6a54782..0ab07aaee 100644 --- a/src/omv/Makefile +++ b/src/omv/Makefile @@ -1,21 +1,41 @@ # Sources -SRCS += $(addprefix ,\ - main.c\ - systick.c\ - usbdbg.c\ - sccb.c\ - ov9650.c\ - ov2640.c\ - sensor.c\ - led.c\ +SRCS += $(addprefix , \ + main.c \ + xalloc.c \ + array.c \ + usbdbg.c \ + systick.c \ + sccb.c \ + ov9650.c \ + ov2640.c \ + sensor.c \ + led.c \ + rng.c \ ) -SRCS += $(addprefix img/,\ +SRCS += $(addprefix img/, \ + blob.c \ + fmath.c \ + haar.c \ + imlib.c \ + integral.c \ + kmeans.c \ + lab.c \ + median.c \ + point.c \ + ppm.c \ + rectangle.c \ + surf.c \ + template.c \ ) -SRCS += $(addprefix py/,\ - py_led.c\ - py_sensor.c\ +SRCS += $(addprefix py/, \ + py_led.c \ + py_sensor.c \ + py_image.c \ + py_file.c \ + py_time.c \ + py_clock.c \ ) OBJS = $(addprefix $(BUILD)/, $(SRCS:.c=.o)) diff --git a/src/omv/img/blob.c b/src/omv/img/blob.c index 196a723b4..3427f4051 100644 --- a/src/omv/img/blob.c +++ b/src/omv/img/blob.c @@ -1,4 +1,3 @@ -#include #include "xalloc.h" #include "imlib.h" #include diff --git a/src/omv/img/haar.c b/src/omv/img/haar.c index aee6cb276..80c6dea60 100644 --- a/src/omv/img/haar.c +++ b/src/omv/img/haar.c @@ -1,4 +1,5 @@ -#include +#include +#include #include "xalloc.h" #include "imlib.h" #include diff --git a/src/omv/img/median.c b/src/omv/img/median.c index ff2b24f98..d61138bae 100644 --- a/src/omv/img/median.c +++ b/src/omv/img/median.c @@ -1,4 +1,3 @@ -#include #include "xalloc.h" #include "imlib.h" #include diff --git a/src/omv/img/ppm.c b/src/omv/img/ppm.c index 207b47e2a..03ae94a55 100644 --- a/src/omv/img/ppm.c +++ b/src/omv/img/ppm.c @@ -1,4 +1,5 @@ -#include +#include +#include #include "xalloc.h" #include "imlib.h" #include "mdefs.h" diff --git a/src/omv/img/template.c b/src/omv/img/template.c index 043e535c0..6907433e0 100644 --- a/src/omv/img/template.c +++ b/src/omv/img/template.c @@ -1,4 +1,3 @@ -#include #include "xalloc.h" #include "imlib.h" #include diff --git a/src/omv/main.c b/src/omv/main.c index dc46c75c4..c18e0ec01 100644 --- a/src/omv/main.c +++ b/src/omv/main.c @@ -22,21 +22,20 @@ #include "timer.h" #include "pin.h" #include "extint.h" -#include "usrsw.h" #include "usb.h" #include "rtc.h" #include "storage.h" #include "sdcard.h" #include "ff.h" -#include "lcd.h" #include "mdefs.h" +#include "led.h" +#include "rng.h" +#include "sensor.h" #include "usbdbg.h" -#include "led.h" #include "py_led.h" - -#include "sensor.h" +#include "py_time.h" #include "py_sensor.h" int errno; @@ -110,12 +109,17 @@ STATIC mp_obj_t pyb_usb_mode(mp_obj_t usb_mode) { MP_DEFINE_CONST_FUN_OBJ_1(pyb_usb_mode_obj, pyb_usb_mode); +STATIC mp_obj_t py_vcp_is_connected(void ) { + return MP_BOOL(usb_vcp_is_connected()); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(py_vcp_is_connected_obj, py_vcp_is_connected); + static const char fresh_main_py[] = "# main.py -- put your code here!\n" "import led, sensor\n" "led.on(led.BLUE)\n" "sensor.set_pixformat(sensor.RGB565)\n" -"while (True):\n" +"while (vcp_is_connected()==False):\n" " image = sensor.snapshot()\n" ; @@ -146,7 +150,7 @@ typedef struct { static const module_t exported_modules[] ={ {MP_QSTR_sensor,py_sensor_init}, {MP_QSTR_led, py_led_init}, -// {MP_QSTR_time, py_time_init}, + {MP_QSTR_time, py_time_init}, // {MP_QSTR_gpio, py_gpio_init}, // {MP_QSTR_spi, py_spi_init}, {0, NULL} @@ -333,15 +337,12 @@ soft_reset: timer_init0(); + rng_init(); usbdbg_init(); -#if MICROPY_HW_ENABLE_RNG - //rng_init0(); -#endif - /* Add functions to the global python namespace */ // mp_store_global(qstr_from_str("open"), mp_make_function_n(2, py_file_open)); -// mp_store_global(qstr_from_str("vcp_connected"), mp_make_function_n(0, py_vcp_connected)); + mp_store_global(qstr_from_str("vcp_is_connected"), mp_make_function_n(0, py_vcp_is_connected)); // mp_store_global(qstr_from_str("info"), mp_make_function_n(0, py_info)); // mp_store_global(qstr_from_str("gc_collect"), mp_make_function_n(0, py_gc_collect)); // mp_store_global(qstr_from_str("Image"), mp_make_function_n(1, py_image_load_image)); diff --git a/src/omv/py/py_clock.c b/src/omv/py/py_clock.c index e524016fd..da17f1ead 100644 --- a/src/omv/py/py_clock.c +++ b/src/omv/py/py_clock.c @@ -1,4 +1,4 @@ -#include +#include #include "systick.h" #include "py_clock.h" diff --git a/src/omv/py/py_file.c b/src/omv/py/py_file.c index 69024b1a9..dc867568b 100644 --- a/src/omv/py/py_file.c +++ b/src/omv/py/py_file.c @@ -1,4 +1,4 @@ -#include +#include #include "py_assert.h" #include "py_file.h" typedef struct _py_file_obj_t { diff --git a/src/omv/py/py_image.c b/src/omv/py/py_image.c index 0cdafd119..c8c8991fe 100644 --- a/src/omv/py/py_image.c +++ b/src/omv/py/py_image.c @@ -4,6 +4,7 @@ #include "sensor.h" #include "py_assert.h" #include "py_image.h" +#include "ff.h" extern struct sensor_dev sensor; static const mp_obj_type_t py_cascade_type; diff --git a/src/omv/py/py_sensor.c b/src/omv/py/py_sensor.c index 6ac034fdd..9528654d6 100644 --- a/src/omv/py/py_sensor.c +++ b/src/omv/py/py_sensor.c @@ -15,11 +15,9 @@ static mp_obj_t py_sensor_reset() { } static mp_obj_t py_sensor_snapshot() { -// mp_obj_t image = py_image(0, 0, 0, 0); -// sensor_snapshot((struct image*) py_image_cobj(image)); -// return image; - sensor_snapshot(0); - return mp_const_none; + mp_obj_t image = py_image(0, 0, 0, 0); + sensor_snapshot((struct image*) py_image_cobj(image)); + return image; } static mp_obj_t py_sensor_set_pixformat(mp_obj_t pixformat) { diff --git a/src/omv/py/py_time.c b/src/omv/py/py_time.c index 558ae01c6..4425d9551 100644 --- a/src/omv/py/py_time.c +++ b/src/omv/py/py_time.c @@ -1,4 +1,4 @@ -#include +#include #include "systick.h" #include "py_time.h" #include "py_clock.h" diff --git a/src/omv/rng.c b/src/omv/rng.c index 069e12268..e93ea1770 100644 --- a/src/omv/rng.c +++ b/src/omv/rng.c @@ -1,19 +1,26 @@ -#include -#include +#include #include "rng.h" +static RNG_HandleTypeDef RNGHandle; + void rng_init() { - RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE); - RNG_Cmd(ENABLE); + __RNG_CLK_ENABLE(); + + RNGHandle.Instance = RNG; + __HAL_RNG_ENABLE(&RNGHandle); } uint32_t rng_randint(uint32_t min, uint32_t max) { - uint32_t rand; + uint32_t rand=0; if (min==max) { return 0; } - rand = RNG_GetRandomNumber(); + + // Wait until the RNG is ready + while (HAL_RNG_GetState(&RNGHandle) != RNG_FLAG_DRDY); + + rand = HAL_RNG_GetRandomNumber(&RNGHandle); return (rand%(max-min))+min; } diff --git a/src/omv/sensor.c b/src/omv/sensor.c index 4dad97a96..2b0032f1e 100644 --- a/src/omv/sensor.c +++ b/src/omv/sensor.c @@ -349,11 +349,16 @@ int sensor_snapshot(struct image *image) /* Enable the Frame capture complete interrupt */ __HAL_DCMI_ENABLE_IT(&DCMIHandle, DCMI_IT_FRAME); - HAL_DCMI_Start_DMA(&DCMIHandle, DCMI_MODE_SNAPSHOT, (uint32_t) fb->pixels, (fb->w * fb->h * 2)/4); + if (sensor.pixformat==PIXFORMAT_GRAYSCALE) { + HAL_DCMI_Start_DMA(&DCMIHandle, DCMI_MODE_SNAPSHOT, (uint32_t) fb->pixels+(fb->w * fb->h), (fb->w * fb->h * 2)/4); + } else { + HAL_DCMI_Start_DMA(&DCMIHandle, DCMI_MODE_SNAPSHOT, (uint32_t) fb->pixels, (fb->w * fb->h * 2)/4); + } /* Wait for frame */ while (HAL_DCMI_GetState(&DCMIHandle) == HAL_DCMI_STATE_BUSY); +#if 0 if (sensor.pixformat == PIXFORMAT_GRAYSCALE) { /* Extract Y channel from YUYV */ for (int i=0; i<(fb->w * fb->h); i++) { @@ -361,10 +366,22 @@ int sensor_snapshot(struct image *image) } } -// image->w = fb->w; -// image->h = fb->h; -// image->bpp = fb->bpp; -// image->pixels = fb->pixels; +#endif + + if (sensor.pixformat == PIXFORMAT_GRAYSCALE) { + int i; + /* extract Y channel */ + for (i=0; i<(fb->w * fb->h); i++) { + fb->pixels[i] = fb->pixels[i*2+(fb->w * fb->h)]; + } + } + + if (image != NULL) { + image->w = fb->w; + image->h = fb->h; + image->bpp = fb->bpp; + image->pixels = fb->pixels; + } return 0; } diff --git a/src/omv/systick.c b/src/omv/systick.c index 4c5cb6490..f74ce3e47 100644 --- a/src/omv/systick.c +++ b/src/omv/systick.c @@ -23,4 +23,5 @@ uint32_t systick_current_millis() bool sys_tick_has_passed(uint32_t stc, uint32_t delay_ms) { systick_sleep(delay_ms); + return true; } diff --git a/src/omv/xalloc.c b/src/omv/xalloc.c index baf05b90c..6edcbb845 100644 --- a/src/omv/xalloc.c +++ b/src/omv/xalloc.c @@ -1,4 +1,4 @@ -#include +#include #include "mdefs.h" #include "xalloc.h"