diff options
| author | Keith Packard <keithp@keithp.com> | 2012-04-07 18:55:20 -0700 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2012-04-07 18:55:20 -0700 | 
| commit | 9b9357f48597a034211affb3f18fc6089816456d (patch) | |
| tree | e34ba9dc0dde3ad5c1dc2cafe412dc26c22381e3 | |
| parent | b5e9d14b4e3e8f29ad8a7bb9b339890be4bcfa2f (diff) | |
altos: Add ADC tests to stm-demo
Signed-off-by: Keith Packard <keithp@keithp.com>
| -rw-r--r-- | src/stm-demo/Makefile | 5 | ||||
| -rw-r--r-- | src/stm-demo/ao_demo.c | 24 | ||||
| -rw-r--r-- | src/stm-demo/ao_pins.h | 25 | 
3 files changed, 41 insertions, 13 deletions
| diff --git a/src/stm-demo/Makefile b/src/stm-demo/Makefile index c1f49371..26c81a82 100644 --- a/src/stm-demo/Makefile +++ b/src/stm-demo/Makefile @@ -29,13 +29,14 @@ ALTOS_SRC = \  	ao_lcd_font.c \  	ao_mutex.c \  	ao_dma_stm.c \ -	ao_spi_stm.c  +	ao_spi_stm.c \ +	ao_adc_stm.c  PRODUCT=StmDemo-v0.0  PRODUCT_DEF=-DSTM_DEMO  IDPRODUCT=0x000a -CFLAGS = $(PRODUCT_DEF) $(STM_CFLAGS) -g -Os +CFLAGS = $(PRODUCT_DEF) $(STM_CFLAGS) -g -O0  PROG=stm-demo diff --git a/src/stm-demo/ao_demo.c b/src/stm-demo/ao_demo.c index 5ff2b32a..63647aac 100644 --- a/src/stm-demo/ao_demo.c +++ b/src/stm-demo/ao_demo.c @@ -51,13 +51,15 @@ void _exit () { }  void _read () { }  void _fstat() { } +#define AO_DMA_TEST_INDEX	STM_DMA_INDEX(4) +  static void  ao_dma_test(void) {  	static char	src[20] = "hello, world";  	static char	dst[20];  	dst[0] = '\0'; -	ao_dma_set_transfer(STM_DMA_INDEX(1), dst, src, 13, +	ao_dma_set_transfer(AO_DMA_TEST_INDEX, dst, src, 13,  			    (1 << STM_DMA_CCR_MEM2MEM) |  			    (STM_DMA_CCR_PL_LOW << STM_DMA_CCR_PL) |  			    (STM_DMA_CCR_MSIZE_8 << STM_DMA_CCR_MSIZE) | @@ -66,11 +68,12 @@ ao_dma_test(void) {  			    (1 << STM_DMA_CCR_PINC) |  			    (0 << STM_DMA_CCR_CIRC) |  			    (STM_DMA_CCR_DIR_MEM_TO_PER << STM_DMA_CCR_DIR)); -	ao_dma_start(STM_DMA_INDEX(1)); -	cli(); -	while (!ao_dma_done[STM_DMA_INDEX(1)]) -		ao_sleep(&ao_dma_done[STM_DMA_INDEX(1)]); -	sei(); +	ao_dma_start(AO_DMA_TEST_INDEX); +	ao_arch_critical( +		while (!ao_dma_done[AO_DMA_TEST_INDEX]) +			ao_sleep(&ao_dma_done[AO_DMA_TEST_INDEX]); +		); +	ao_dma_done_transfer(AO_DMA_TEST_INDEX);  	printf ("copied %s\n", dst);  } @@ -128,13 +131,12 @@ main(void)  //	ao_lcd_font_init();  	ao_spi_init(); +	ao_timer_set_adc_interval(100); + +	ao_adc_init(); +  	ao_cmd_register(&ao_demo_cmds[0]); -	stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_GPIOCEN); -	stm_gpio_set(&stm_gpioc, 12, 1); -	stm_moder_set(&stm_gpioc, 12, STM_MODER_OUTPUT); -	stm_otyper_set(&stm_gpioc, 12, STM_OTYPER_PUSH_PULL); -  	ao_start_scheduler();  	return 0;  } diff --git a/src/stm-demo/ao_pins.h b/src/stm-demo/ao_pins.h index 09c88f90..fecd8cda 100644 --- a/src/stm-demo/ao_pins.h +++ b/src/stm-demo/ao_pins.h @@ -111,4 +111,29 @@  #define AO_LCD_28_ON_C	1 +#define HAS_ADC			1 + +#define AO_ADC_RING		32 + +struct ao_adc { +	uint16_t		tick; +	int16_t			idd; +	int16_t			temp; +}; + +#define AO_ADC_IDD		4 +#define AO_ADC_PIN0_PORT	stm_gpioa +#define AO_ADC_PIN0_PIN		4 + +#define AO_ADC_RCC_AHBENR	((1 << STM_RCC_AHBENR_GPIOAEN)) +#define AO_ADC_TEMP		16 + +#define HAS_ADC_TEMP		1 + +#define AO_NUM_ADC		2 + +#define AO_ADC_SQ1		AO_ADC_IDD +#define AO_ADC_SQ2		AO_ADC_TEMP +	 +  #endif /* _AO_PINS_H_ */ | 
