altos: Test I2C code on discovery board.
authorKeith Packard <keithp@keithp.com>
Mon, 9 Apr 2012 07:10:43 +0000 (00:10 -0700)
committerKeith Packard <keithp@keithp.com>
Mon, 9 Apr 2012 07:10:43 +0000 (00:10 -0700)
Signed-off-by: Keith Packard <keithp@keithp.com>
src/stm-demo/Makefile
src/stm-demo/ao_demo.c
src/stm-demo/ao_pins.h

index 26c81a822902147d9c3d72f930c60ef6fed9947e..2f156ea4436175752f1e3589950316bf67e57267 100644 (file)
@@ -8,6 +8,7 @@ include ../stm/Makefile.defs
 INC = \
        ao.h \
        ao_arch.h \
+       ao_arch_funcs.h \
        ao_pins.h \
        ao_product.h
 
@@ -30,7 +31,8 @@ ALTOS_SRC = \
        ao_mutex.c \
        ao_dma_stm.c \
        ao_spi_stm.c \
-       ao_adc_stm.c
+       ao_adc_stm.c \
+       ao_i2c_stm.c
 
 PRODUCT=StmDemo-v0.0
 PRODUCT_DEF=-DSTM_DEMO
index ea4dadfa89d438513c1414308569367d525bb947..879f7f75bb4fbdb1cb3c71c67fddb43aa645439d 100644 (file)
@@ -111,7 +111,26 @@ ao_spi_read(void) {
        }
 }
 
+static void
+ao_i2c_write(void) {
+       unsigned char   data[] = { 0x55, 0xaa, 0xff, 0x00 };
+       int i;
 
+       for (i = 0; i < 10; i++) {
+               ao_i2c_get(0);
+               if (ao_i2c_start(0, 0x55))
+                       ao_i2c_send(data, 4, 0);
+               else {
+                       printf ("i2c start failed\n");
+                       ao_i2c_put(0);
+                       break;
+               }
+               ao_i2c_put(0);
+               printf(".");
+               flush();
+               ao_delay(100);
+       }
+}
 
 static void
 ao_temp (void)
@@ -133,6 +152,7 @@ __code struct ao_cmds ao_demo_cmds[] = {
        { ao_dma_test,  "D\0DMA test" },
        { ao_spi_write, "W\0SPI write" },
        { ao_spi_read, "R\0SPI read" },
+       { ao_i2c_write, "i\0I2C write" },
        { ao_temp, "t\0Show temp" },
        { 0, NULL }
 };
@@ -149,6 +169,7 @@ main(void)
 //     ao_lcd_stm_init();
 //     ao_lcd_font_init();
        ao_spi_init();
+       ao_i2c_init();
 
        ao_timer_set_adc_interval(100);
 
index 42f4123d19c1f586bc16463eadc3de1d2bac95f0..9fd1175ddcaaf34a4c6f3daefc427710596bf735 100644 (file)
@@ -138,5 +138,11 @@ struct ao_adc {
 #define AO_ADC_SQ2             AO_ADC_TEMP
 #define AO_ADC_SQ3             AO_ADC_VREF
        
+#define HAS_I2C_1              1
+#define I2C_1_PB6_PB7          0
+#define I2C_1_PB8_PB9          1
+
+#define HAS_I2C_2              0
+#define I2C_2_PB10_PB11                0
 
 #endif /* _AO_PINS_H_ */