diff --git a/examples/ssd1306_12864_4wire_hw_spi_example.c b/examples/ssd1306_12864_4wire_hw_spi_example.c index 9a1e704f..b49ddcc6 100644 --- a/examples/ssd1306_12864_4wire_hw_spi_example.c +++ b/examples/ssd1306_12864_4wire_hw_spi_example.c @@ -6,32 +6,32 @@ // You may reference Drivers/drv_gpio.c for pinout // In u8x8.h #define U8X8_USE_PINS -#define OLED_SPI_PIN_RES 16 // PA2 -#define OLED_SPI_PIN_DC 15 // PA1 -#define OLED_SPI_PIN_CS 14 // PA0 +#define OLED_SPI_PIN_RES 16 // PA2 +#define OLED_SPI_PIN_DC 15 // PA1 +#define OLED_SPI_PIN_CS 14 // PA0 static void ssd1306_12864_4wire_hw_spi_example(int argc,char *argv[]) { - u8g2_t u8g2; + u8g2_t u8g2; - // Initialization - u8g2_Setup_ssd1306_128x64_noname_f( &u8g2, U8G2_R0, u8x8_byte_rt_4wire_hw_spi, u8x8_rt_gpio_and_delay); - u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_CS, OLED_SPI_PIN_CS); - u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_DC, OLED_SPI_PIN_DC); - u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_RESET, OLED_SPI_PIN_RES); + // Initialization + u8g2_Setup_ssd1306_128x64_noname_f( &u8g2, U8G2_R0, u8x8_byte_rt_4wire_hw_spi, u8x8_rt_gpio_and_delay); + u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_CS, OLED_SPI_PIN_CS); + u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_DC, OLED_SPI_PIN_DC); + u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_RESET, OLED_SPI_PIN_RES); + + u8g2_InitDisplay(&u8g2); + u8g2_SetPowerSave(&u8g2, 0); - u8g2_InitDisplay(&u8g2); - u8g2_SetPowerSave(&u8g2, 0); - - // Draw Graphics - /* full buffer example, setup procedure ends in _f */ - u8g2_ClearBuffer(&u8g2); - u8g2_SetFont(&u8g2, u8g2_font_baby_tf); - u8g2_DrawStr(&u8g2, 1, 18, "U8g2 on RT-Thread"); - u8g2_SendBuffer(&u8g2); + // Draw Graphics + /* full buffer example, setup procedure ends in _f */ + u8g2_ClearBuffer(&u8g2); + u8g2_SetFont(&u8g2, u8g2_font_baby_tf); + u8g2_DrawStr(&u8g2, 1, 18, "U8g2 on RT-Thread"); + u8g2_SendBuffer(&u8g2); - u8g2_SetFont(&u8g2, u8g2_font_unifont_t_symbols); - u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 ); - u8g2_SendBuffer(&u8g2); + u8g2_SetFont(&u8g2, u8g2_font_unifont_t_symbols); + u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 ); + u8g2_SendBuffer(&u8g2); } MSH_CMD_EXPORT(ssd1306_12864_4wire_hw_spi_example, sw 4wire spi ssd1306 sample); diff --git a/examples/ssd1306_12864_4wire_sw_spi_example.c b/examples/ssd1306_12864_4wire_sw_spi_example.c index f9446133..2b51ad52 100644 --- a/examples/ssd1306_12864_4wire_sw_spi_example.c +++ b/examples/ssd1306_12864_4wire_sw_spi_example.c @@ -6,36 +6,36 @@ // You may reference Drivers/drv_gpio.c for pinout // In u8x8.h #define U8X8_USE_PINS -#define OLED_SPI_PIN_CLK 21 // PA5 -#define OLED_SPI_PIN_MOSI 23 // PA7 -#define OLED_SPI_PIN_RES 16 // PA2 -#define OLED_SPI_PIN_DC 15 // PA1 -#define OLED_SPI_PIN_CS 14 // PA0 +#define OLED_SPI_PIN_CLK 21 // PA5 +#define OLED_SPI_PIN_MOSI 23 // PA7 +#define OLED_SPI_PIN_RES 16 // PA2 +#define OLED_SPI_PIN_DC 15 // PA1 +#define OLED_SPI_PIN_CS 14 // PA0 static void ssd1306_12864_4wire_sw_spi_example(int argc,char *argv[]) { - u8g2_t u8g2; + u8g2_t u8g2; - // Initialization - u8g2_Setup_ssd1306_128x64_noname_f( &u8g2, U8G2_R0, u8x8_byte_4wire_sw_spi, u8x8_rt_gpio_and_delay); - u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_SPI_CLOCK, OLED_SPI_PIN_CLK); - u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_SPI_DATA, OLED_SPI_PIN_MOSI); - u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_CS, OLED_SPI_PIN_CS); - u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_DC, OLED_SPI_PIN_DC); - u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_RESET, OLED_SPI_PIN_RES); - - u8g2_InitDisplay(&u8g2); - u8g2_SetPowerSave(&u8g2, 0); - - // Draw Graphics - /* full buffer example, setup procedure ends in _f */ - u8g2_ClearBuffer(&u8g2); - u8g2_SetFont(&u8g2, u8g2_font_baby_tf); - u8g2_DrawStr(&u8g2, 1, 18, "U8g2 on RT-Thread"); - u8g2_SendBuffer(&u8g2); + // Initialization + u8g2_Setup_ssd1306_128x64_noname_f( &u8g2, U8G2_R0, u8x8_byte_4wire_sw_spi, u8x8_rt_gpio_and_delay); + u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_SPI_CLOCK, OLED_SPI_PIN_CLK); + u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_SPI_DATA, OLED_SPI_PIN_MOSI); + u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_CS, OLED_SPI_PIN_CS); + u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_DC, OLED_SPI_PIN_DC); + u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_RESET, OLED_SPI_PIN_RES); - u8g2_SetFont(&u8g2, u8g2_font_unifont_t_symbols); - u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 ); - u8g2_SendBuffer(&u8g2); + u8g2_InitDisplay(&u8g2); + u8g2_SetPowerSave(&u8g2, 0); + + // Draw Graphics + /* full buffer example, setup procedure ends in _f */ + u8g2_ClearBuffer(&u8g2); + u8g2_SetFont(&u8g2, u8g2_font_baby_tf); + u8g2_DrawStr(&u8g2, 1, 18, "U8g2 on RT-Thread"); + u8g2_SendBuffer(&u8g2); + + u8g2_SetFont(&u8g2, u8g2_font_unifont_t_symbols); + u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 ); + u8g2_SendBuffer(&u8g2); } MSH_CMD_EXPORT(ssd1306_12864_4wire_sw_spi_example, sw 4wire spi ssd1306 sample); diff --git a/examples/ssd1306_12864_hw_i2c_example.c b/examples/ssd1306_12864_hw_i2c_example.c index 0f05611f..20fe3d69 100644 --- a/examples/ssd1306_12864_hw_i2c_example.c +++ b/examples/ssd1306_12864_hw_i2c_example.c @@ -5,22 +5,22 @@ static void ssd1306_12864_hw_i2c_example(int argc,char *argv[]) { - u8g2_t u8g2; - - // Initialization - u8g2_Setup_ssd1306_i2c_128x64_noname_f( &u8g2, U8G2_R0, u8x8_byte_rt_hw_i2c, u8x8_rt_gpio_and_delay); - u8g2_InitDisplay(&u8g2); - u8g2_SetPowerSave(&u8g2, 0); - - /* full buffer example, setup procedure ends in _f */ - u8g2_ClearBuffer(&u8g2); - u8g2_SetFont(&u8g2, u8g2_font_ncenB08_tr); - u8g2_DrawStr(&u8g2, 1, 18, "U8g2 on RT-Thread"); - u8g2_SendBuffer(&u8g2); + u8g2_t u8g2; - // Draw Graphics - u8g2_SetFont(&u8g2, u8g2_font_unifont_t_symbols); - u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 ); - u8g2_SendBuffer(&u8g2); + // Initialization + u8g2_Setup_ssd1306_i2c_128x64_noname_f( &u8g2, U8G2_R0, u8x8_byte_rt_hw_i2c, u8x8_rt_gpio_and_delay); + u8g2_InitDisplay(&u8g2); + u8g2_SetPowerSave(&u8g2, 0); + + /* full buffer example, setup procedure ends in _f */ + u8g2_ClearBuffer(&u8g2); + u8g2_SetFont(&u8g2, u8g2_font_ncenB08_tr); + u8g2_DrawStr(&u8g2, 1, 18, "U8g2 on RT-Thread"); + u8g2_SendBuffer(&u8g2); + + // Draw Graphics + u8g2_SetFont(&u8g2, u8g2_font_unifont_t_symbols); + u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 ); + u8g2_SendBuffer(&u8g2); } MSH_CMD_EXPORT(ssd1306_12864_hw_i2c_example, i2c ssd1306 sample); diff --git a/examples/ssd1306_12864_sw_i2c_example.c b/examples/ssd1306_12864_sw_i2c_example.c index 49755f2a..d7eadd8f 100644 --- a/examples/ssd1306_12864_sw_i2c_example.c +++ b/examples/ssd1306_12864_sw_i2c_example.c @@ -3,30 +3,30 @@ #include #include -#define OLED_I2C_PIN_SCL 58 // PB6 -#define OLED_I2C_PIN_SDA 59 // PB7 +#define OLED_I2C_PIN_SCL 58 // PB6 +#define OLED_I2C_PIN_SDA 59 // PB7 static void ssd1306_12864_sw_i2c_example(int argc,char *argv[]) { - u8g2_t u8g2; - - // Initialization - u8g2_Setup_ssd1306_i2c_128x64_noname_f( &u8g2, U8G2_R0, u8x8_byte_sw_i2c, u8x8_rt_gpio_and_delay); - u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_I2C_CLOCK, OLED_I2C_PIN_SCL); - u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_I2C_DATA, OLED_I2C_PIN_SDA); + u8g2_t u8g2; - u8g2_InitDisplay(&u8g2); - u8g2_SetPowerSave(&u8g2, 0); - - // Draw Graphics - /* full buffer example, setup procedure ends in _f */ - u8g2_ClearBuffer(&u8g2); - u8g2_SetFont(&u8g2, u8g2_font_ncenB08_tr); - u8g2_DrawStr(&u8g2, 1, 18, "U8g2 on RT-Thread"); - u8g2_SendBuffer(&u8g2); + // Initialization + u8g2_Setup_ssd1306_i2c_128x64_noname_f( &u8g2, U8G2_R0, u8x8_byte_sw_i2c, u8x8_rt_gpio_and_delay); + u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_I2C_CLOCK, OLED_I2C_PIN_SCL); + u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_I2C_DATA, OLED_I2C_PIN_SDA); - u8g2_SetFont(&u8g2, u8g2_font_unifont_t_symbols); - u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 ); - u8g2_SendBuffer(&u8g2); + u8g2_InitDisplay(&u8g2); + u8g2_SetPowerSave(&u8g2, 0); + + // Draw Graphics + /* full buffer example, setup procedure ends in _f */ + u8g2_ClearBuffer(&u8g2); + u8g2_SetFont(&u8g2, u8g2_font_ncenB08_tr); + u8g2_DrawStr(&u8g2, 1, 18, "U8g2 on RT-Thread"); + u8g2_SendBuffer(&u8g2); + + u8g2_SetFont(&u8g2, u8g2_font_unifont_t_symbols); + u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 ); + u8g2_SendBuffer(&u8g2); } MSH_CMD_EXPORT(ssd1306_12864_sw_i2c_example, i2c ssd1306 software i2c sample); diff --git a/examples/st7920_12864_8080_example.c b/examples/st7920_12864_8080_example.c index a347f666..80293a76 100644 --- a/examples/st7920_12864_8080_example.c +++ b/examples/st7920_12864_8080_example.c @@ -6,61 +6,61 @@ // You may reference Drivers/drv_gpio.c for pinout // In u8x8.h #define U8X8_USE_PINS -#define ST7920_8080_PIN_D0 36 // PB15 -#define ST7920_8080_PIN_D1 35 // PB14 -#define ST7920_8080_PIN_D2 34 // PB13 -#define ST7920_8080_PIN_D3 33 // PB12 -#define ST7920_8080_PIN_D4 37 // PC6 -#define ST7920_8080_PIN_D5 38 // PC7 -#define ST7920_8080_PIN_D6 39 // PC8 -#define ST7920_8080_PIN_D7 40 // PC9 -#define ST7920_8080_PIN_EN 50 // PA15 -#define ST7920_8080_PIN_CS U8X8_PIN_NONE -#define ST7920_8080_PIN_DC 44 // PA11 -#define ST7920_8080_PIN_RST 45 // PA12 +#define ST7920_8080_PIN_D0 36 // PB15 +#define ST7920_8080_PIN_D1 35 // PB14 +#define ST7920_8080_PIN_D2 34 // PB13 +#define ST7920_8080_PIN_D3 33 // PB12 +#define ST7920_8080_PIN_D4 37 // PC6 +#define ST7920_8080_PIN_D5 38 // PC7 +#define ST7920_8080_PIN_D6 39 // PC8 +#define ST7920_8080_PIN_D7 40 // PC9 +#define ST7920_8080_PIN_EN 50 // PA15 +#define ST7920_8080_PIN_CS U8X8_PIN_NONE +#define ST7920_8080_PIN_DC 44 // PA11 +#define ST7920_8080_PIN_RST 45 // PA12 void u8x8_SetPin_8Bit_8080(u8x8_t *u8x8, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7, uint8_t wr, uint8_t cs, uint8_t dc, uint8_t reset) { - u8x8_SetPin(u8x8, U8X8_PIN_D0, d0); - u8x8_SetPin(u8x8, U8X8_PIN_D1, d1); - u8x8_SetPin(u8x8, U8X8_PIN_D2, d2); - u8x8_SetPin(u8x8, U8X8_PIN_D3, d3); - u8x8_SetPin(u8x8, U8X8_PIN_D4, d4); - u8x8_SetPin(u8x8, U8X8_PIN_D5, d5); - u8x8_SetPin(u8x8, U8X8_PIN_D6, d6); - u8x8_SetPin(u8x8, U8X8_PIN_D7, d7); - u8x8_SetPin(u8x8, U8X8_PIN_E, wr); - u8x8_SetPin(u8x8, U8X8_PIN_CS, cs); - u8x8_SetPin(u8x8, U8X8_PIN_DC, dc); - u8x8_SetPin(u8x8, U8X8_PIN_RESET, reset); + u8x8_SetPin(u8x8, U8X8_PIN_D0, d0); + u8x8_SetPin(u8x8, U8X8_PIN_D1, d1); + u8x8_SetPin(u8x8, U8X8_PIN_D2, d2); + u8x8_SetPin(u8x8, U8X8_PIN_D3, d3); + u8x8_SetPin(u8x8, U8X8_PIN_D4, d4); + u8x8_SetPin(u8x8, U8X8_PIN_D5, d5); + u8x8_SetPin(u8x8, U8X8_PIN_D6, d6); + u8x8_SetPin(u8x8, U8X8_PIN_D7, d7); + u8x8_SetPin(u8x8, U8X8_PIN_E, wr); + u8x8_SetPin(u8x8, U8X8_PIN_CS, cs); + u8x8_SetPin(u8x8, U8X8_PIN_DC, dc); + u8x8_SetPin(u8x8, U8X8_PIN_RESET, reset); } static void st7920_12864_8080_example(int argc,char *argv[]) { - u8g2_t u8g2; + u8g2_t u8g2; - // Initialization - u8g2_Setup_st7920_p_128x64_f(&u8g2, U8G2_R0, u8x8_byte_8bit_8080mode, u8x8_rt_gpio_and_delay); - u8x8_SetPin_8Bit_8080(u8g2_GetU8x8(&u8g2), - ST7920_8080_PIN_D0, ST7920_8080_PIN_D1, - ST7920_8080_PIN_D2, ST7920_8080_PIN_D3, - ST7920_8080_PIN_D4, ST7920_8080_PIN_D5, - ST7920_8080_PIN_D6, ST7920_8080_PIN_D7, - ST7920_8080_PIN_EN, ST7920_8080_PIN_CS, - ST7920_8080_PIN_DC, ST7920_8080_PIN_RST); - - u8g2_InitDisplay(&u8g2); - u8g2_SetPowerSave(&u8g2, 0); - - // Draw Graphics - /* full buffer example, setup procedure ends in _f */ - u8g2_ClearBuffer(&u8g2); - u8g2_SetFont(&u8g2, u8g2_font_baby_tf); - u8g2_DrawStr(&u8g2, 1, 18, "U8g2 on RT-Thread"); - u8g2_SendBuffer(&u8g2); + // Initialization + u8g2_Setup_st7920_p_128x64_f(&u8g2, U8G2_R0, u8x8_byte_8bit_8080mode, u8x8_rt_gpio_and_delay); + u8x8_SetPin_8Bit_8080(u8g2_GetU8x8(&u8g2), + ST7920_8080_PIN_D0, ST7920_8080_PIN_D1, + ST7920_8080_PIN_D2, ST7920_8080_PIN_D3, + ST7920_8080_PIN_D4, ST7920_8080_PIN_D5, + ST7920_8080_PIN_D6, ST7920_8080_PIN_D7, + ST7920_8080_PIN_EN, ST7920_8080_PIN_CS, + ST7920_8080_PIN_DC, ST7920_8080_PIN_RST); - u8g2_SetFont(&u8g2, u8g2_font_unifont_t_symbols); - u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 ); - u8g2_SendBuffer(&u8g2); + u8g2_InitDisplay(&u8g2); + u8g2_SetPowerSave(&u8g2, 0); + + // Draw Graphics + /* full buffer example, setup procedure ends in _f */ + u8g2_ClearBuffer(&u8g2); + u8g2_SetFont(&u8g2, u8g2_font_baby_tf); + u8g2_DrawStr(&u8g2, 1, 18, "U8g2 on RT-Thread"); + u8g2_SendBuffer(&u8g2); + + u8g2_SetFont(&u8g2, u8g2_font_unifont_t_symbols); + u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 ); + u8g2_SendBuffer(&u8g2); } MSH_CMD_EXPORT(st7920_12864_8080_example, st7920 12864 LCD sample); diff --git a/examples/yl_40_example.c b/examples/yl_40_example.c index 8953499c..0c5f5da5 100644 --- a/examples/yl_40_example.c +++ b/examples/yl_40_example.c @@ -4,53 +4,51 @@ #include #include -const char* yl_40_bus = "i2c2"; - -static void yl_40_example(int argc,char *argv[]) +static void yl_40_example(int argc, char *argv[]) { - struct rt_i2c_bus_device *yl40_bus = RT_NULL; - - yl40_bus = rt_i2c_bus_device_find(yl_40_bus); - - rt_uint8_t t = 0; - if (yl40_bus == RT_NULL) - { - rt_kprintf("Failed to find bus\n"); - } - else - { - struct rt_i2c_msg msgs; - static uint8_t buffer[2]; - buffer[0] = 0xff; - if(argc == 2) - { - buffer[1] = atoi(argv[1]); - } - else if(argc == 3) - { - buffer[1] = atoi(argv[2]); - } - else - { - buffer[1] = 0x88; - } - - if(argc >= 3) - { - msgs.addr = (int)strtol(argv[1], NULL, 0); - } - else - { - msgs.addr = 0x48; - } + struct rt_i2c_bus_device *yl40_bus = RT_NULL; + + yl40_bus = rt_i2c_bus_device_find(U8G2_I2C_DEVICE_NAME); + + rt_uint8_t t = 0; + if (yl40_bus == RT_NULL) + { + rt_kprintf("Failed to find bus\n"); + } + else + { + struct rt_i2c_msg msgs; + static uint8_t buffer[2]; + buffer[0] = 0xff; + if(argc == 2) + { + buffer[1] = atoi(argv[1]); + } + else if(argc == 3) + { + buffer[1] = atoi(argv[2]); + } + else + { + buffer[1] = 0x88; + } + + if(argc >= 3) + { + msgs.addr = (int)strtol(argv[1], NULL, 0); + } + else + { + msgs.addr = 0x48; + } - msgs.flags = RT_I2C_WR; - msgs.buf = buffer; - msgs.len = 2; - while(rt_i2c_transfer(yl40_bus, &msgs, 1) != 1 && t < 3) - { - t++; - }; - } + msgs.flags = RT_I2C_WR; + msgs.buf = buffer; + msgs.len = 2; + while(rt_i2c_transfer(yl40_bus, &msgs, 1) != 1 && t < 3) + { + t++; + }; + } } MSH_CMD_EXPORT(yl_40_example, i2c yl-40 sample);