Added RES arg to init_i2c_sw and CS arg to init_spi_hw

This commit is contained in:
servadmin 2021-11-15 11:25:06 -05:00
parent 24823f8d95
commit db309408a9
11 changed files with 121 additions and 117 deletions

View File

@ -8,7 +8,7 @@
#define OLED_SPI_PIN_DC 198
// CS pin is controlled by linux spi driver, thus not defined here, but need to be wired
// #define OLED_SPI_PIN_CS 0
#define OLED_SPI_PIN_CS U8X8_PIN_NONE
int main(void) {
u8g2_t u8g2;
@ -16,7 +16,8 @@ int main(void) {
// Initialization
u8g2_Setup_ssd1306_128x64_noname_f(&u8g2, U8G2_R0,
u8x8_byte_arm_linux_hw_spi, u8x8_arm_linux_gpio_and_delay);
init_spi_hw(&u8g2, GPIO_CHIP_NUM, SPI_BUS, OLED_SPI_PIN_DC, OLED_SPI_PIN_RES);
init_spi_hw(&u8g2, GPIO_CHIP_NUM, SPI_BUS, OLED_SPI_PIN_DC,
OLED_SPI_PIN_RES, OLED_SPI_PIN_CS);
u8g2_InitDisplay(&u8g2);
u8g2_ClearBuffer(&u8g2);

View File

@ -18,7 +18,7 @@ int main(void) {
u8g2_Setup_ssd1306_128x64_noname_f(&u8g2, U8G2_R0, u8x8_byte_4wire_sw_spi,
u8x8_arm_linux_gpio_and_delay);
init_spi_sw(&u8g2, GPIO_CHIP_NUM, OLED_SPI_PIN_DC, OLED_SPI_PIN_RES,
OLED_SPI_PIN_MOSI, OLED_SPI_PIN_SCK, OLED_SPI_PIN_CS, 0);
OLED_SPI_PIN_MOSI, OLED_SPI_PIN_SCK, OLED_SPI_PIN_CS, 0);
u8g2_InitDisplay(&u8g2);
u8g2_SetPowerSave(&u8g2, 0);

View File

@ -4,37 +4,37 @@
#define I2C_BUS 0
#define I2C_ADDRESS 0x3c * 2
int main(void)
{
u8g2_t u8g2;
int main(void) {
u8g2_t u8g2;
// Initialization
u8g2_Setup_ssd1306_i2c_128x64_noname_f(&u8g2, U8G2_R0, u8x8_byte_arm_linux_hw_i2c, u8x8_arm_linux_gpio_and_delay);
init_i2c_hw(&u8g2, I2C_BUS);
u8g2_SetI2CAddress(&u8g2, I2C_ADDRESS);
u8g2_InitDisplay(&u8g2);
u8g2_SetPowerSave(&u8g2, 0);
// Initialization
u8g2_Setup_ssd1306_i2c_128x64_noname_f(&u8g2, U8G2_R0,
u8x8_byte_arm_linux_hw_i2c, u8x8_arm_linux_gpio_and_delay);
init_i2c_hw(&u8g2, I2C_BUS);
u8g2_SetI2CAddress(&u8g2, I2C_ADDRESS);
u8g2_InitDisplay(&u8g2);
u8g2_SetPowerSave(&u8g2, 0);
// Draw
/* full buffer example, setup procedure ends in _f */
u8g2_ClearBuffer(&u8g2);
// Draw
/* full buffer example, setup procedure ends in _f */
u8g2_ClearBuffer(&u8g2);
u8g2_SetFont(&u8g2, u8g2_font_ncenB08_tr);
u8g2_DrawStr(&u8g2, 1, 18, "U8g2 HW I2C");
u8g2_SetFont(&u8g2, u8g2_font_ncenB08_tr);
u8g2_DrawStr(&u8g2, 1, 18, "U8g2 HW I2C");
u8g2_SetFont(&u8g2, u8g2_font_unifont_t_symbols);
u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 );
u8g2_SetFont(&u8g2, u8g2_font_unifont_t_symbols);
u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603);
u8g2_SendBuffer(&u8g2);
u8g2_SendBuffer(&u8g2);
printf("Initialized ...\n");
sleep_ms(5000);
u8g2_SetPowerSave(&u8g2, 1);
// Close and deallocate i2c_t
done_i2c();
// Close and deallocate GPIO resources
done_user_data(&u8g2);
printf("Done\n");
printf("Initialized ...\n");
sleep_ms(5000);
u8g2_SetPowerSave(&u8g2, 1);
// Close and deallocate i2c_t
done_i2c();
// Close and deallocate GPIO resources
done_user_data(&u8g2);
printf("Done\n");
return 0;
return 0;
}

View File

@ -4,36 +4,38 @@
#define GPIO_CHIP_NUM 0
#define OLED_I2C_PIN_SCL 11
#define OLED_I2C_PIN_SDA 12
#define OLED_I2C_PIN_RESET U8X8_PIN_NONE
int main(void)
{
u8g2_t u8g2;
int main(void) {
u8g2_t u8g2;
// Initialization
u8g2_Setup_ssd1306_i2c_128x64_noname_f(&u8g2, U8G2_R0, u8x8_byte_sw_i2c, u8x8_arm_linux_gpio_and_delay);
init_i2c_sw(&u8g2, GPIO_CHIP_NUM, OLED_I2C_PIN_SCL, OLED_I2C_PIN_SDA, 0);
// Initialization
u8g2_Setup_ssd1306_i2c_128x64_noname_f(&u8g2, U8G2_R0, u8x8_byte_sw_i2c,
u8x8_arm_linux_gpio_and_delay);
init_i2c_sw(&u8g2, GPIO_CHIP_NUM, OLED_I2C_PIN_SCL, OLED_I2C_PIN_SDA,
OLED_I2C_PIN_RESET, 0);
u8g2_InitDisplay(&u8g2);
u8g2_SetPowerSave(&u8g2, 0);
u8g2_InitDisplay(&u8g2);
u8g2_SetPowerSave(&u8g2, 0);
// Draw
/* full buffer example, setup procedure ends in _f */
u8g2_ClearBuffer(&u8g2);
// Draw
/* full buffer example, setup procedure ends in _f */
u8g2_ClearBuffer(&u8g2);
u8g2_SetFont(&u8g2, u8g2_font_ncenB08_tr);
u8g2_DrawStr(&u8g2, 1, 18, "U8g2 SW I2C");
u8g2_SetFont(&u8g2, u8g2_font_ncenB08_tr);
u8g2_DrawStr(&u8g2, 1, 18, "U8g2 SW I2C");
u8g2_SetFont(&u8g2, u8g2_font_unifont_t_symbols);
u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 );
u8g2_SetFont(&u8g2, u8g2_font_unifont_t_symbols);
u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603);
u8g2_SendBuffer(&u8g2);
u8g2_SendBuffer(&u8g2);
printf("Initialized ...\n");
sleep_ms(5000);
u8g2_SetPowerSave(&u8g2, 1);
// Close and deallocate GPIO resources
done_user_data(&u8g2);
printf("Done\n");
printf("Initialized ...\n");
sleep_ms(5000);
u8g2_SetPowerSave(&u8g2, 1);
// Close and deallocate GPIO resources
done_user_data(&u8g2);
printf("Done\n");
return 0;
return 0;
}

View File

@ -8,7 +8,7 @@
#define OLED_SPI_PIN_DC 198
// CS pin is controlled by linux spi driver
#define OLED_SPI_PIN_CS 0
#define OLED_SPI_PIN_CS U8X8_PIN_NONE
// Check https://github.com/olikraus/u8g2/wiki/u8g2setupcpp for all supported devices
static U8G2_SSD1306_128X64_NONAME_F_4W_HW_SPI u8g2(U8G2_R0,
@ -18,7 +18,8 @@ static U8G2_SSD1306_128X64_NONAME_F_4W_HW_SPI u8g2(U8G2_R0,
// same as the NONAME variant, but may solve the "every 2nd line skipped" problem
int main() {
u8g2.initSpiHw(GPIO_CHIP_NUM, SPI_BUS, OLED_SPI_PIN_DC, OLED_SPI_PIN_RES);
u8g2.initSpiHw(GPIO_CHIP_NUM, SPI_BUS, OLED_SPI_PIN_DC, OLED_SPI_PIN_RES,
OLED_SPI_PIN_CS);
u8g2.begin();
u8g2.setFont(u8g2_font_6x13_tr); // choose a suitable font
u8g2.drawStr(1, 18, "U8g2 on HW SPI"); // write something to the internal memory

View File

@ -11,27 +11,26 @@
#define OLED_SPI_PIN_DC 198
#define OLED_SPI_PIN_CS 13
// Check https://github.com/olikraus/u8g2/wiki/u8g2setupcpp for all supported devices
static U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI u8g2(U8G2_R0,\
/* clock=*/ OLED_SPI_PIN_SCK,\
/* data=*/ OLED_SPI_PIN_MOSI,\
/* cs=*/ OLED_SPI_PIN_CS,\
/* dc=*/ OLED_SPI_PIN_DC,\
/* reset=*/ OLED_SPI_PIN_RES);
static U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI u8g2(U8G2_R0,
/* clock=*/OLED_SPI_PIN_SCK,
/* data=*/OLED_SPI_PIN_MOSI,
/* cs=*/OLED_SPI_PIN_CS,
/* dc=*/OLED_SPI_PIN_DC,
/* reset=*/OLED_SPI_PIN_RES);
int main()
{
u8g2.initSpiSw(GPIO_CHIP_NUM, OLED_SPI_PIN_DC, OLED_SPI_PIN_RES, OLED_SPI_PIN_MOSI, OLED_SPI_PIN_SCK, OLED_SPI_PIN_CS, 0);
u8g2.begin();
u8g2.setFont(u8g2_font_6x13_tr); // choose a suitable font
u8g2.drawStr(1, 18, "U8g2 on SW SPI"); // write something to the internal memory
u8g2.sendBuffer(); // transfer internal memory to the display
u8g2.setFont(u8g2_font_unifont_t_symbols);
u8g2.drawGlyph(112, 56, 0x2603 );
u8g2.sendBuffer();
u8g2.sleepMs(5000);
u8g2.setPowerSave(1);
u8g2.doneUserData();
int main() {
u8g2.initSpiSw(GPIO_CHIP_NUM, OLED_SPI_PIN_DC, OLED_SPI_PIN_RES,
OLED_SPI_PIN_MOSI, OLED_SPI_PIN_SCK, OLED_SPI_PIN_CS, 0);
u8g2.begin();
u8g2.setFont(u8g2_font_6x13_tr); // choose a suitable font
u8g2.drawStr(1, 18, "U8g2 on SW SPI"); // write something to the internal memory
u8g2.sendBuffer(); // transfer internal memory to the display
u8g2.setFont(u8g2_font_unifont_t_symbols);
u8g2.drawGlyph(112, 56, 0x2603);
u8g2.sendBuffer();
u8g2.sleepMs(5000);
u8g2.setPowerSave(1);
u8g2.doneUserData();
}

View File

@ -4,22 +4,22 @@
#define I2C_BUS 0
#define I2C_ADDRESS 0x3c * 2
// Check https://github.com/olikraus/u8g2/wiki/u8g2setupcpp for all supported devices
static U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
static U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/
U8X8_PIN_NONE);
int main(void)
{
// GPIO chip doesn't matter for hardware I2C
int main(void) {
// GPIO chip doesn't matter for hardware I2C
u8g2.initI2cHw(I2C_BUS);
u8g2.setI2CAddress(I2C_ADDRESS);
u8g2.begin();
u8g2.setFont(u8g2_font_6x13_tr); // choose a suitable font
u8g2.drawStr(1, 18, "U8g2 on HW I2C"); // write something to the internal memory
u8g2.sendBuffer(); // transfer internal memory to the display
u8g2.setFont(u8g2_font_unifont_t_symbols);
u8g2.drawGlyph(112, 56, 0x2603 );
u8g2.sendBuffer();
u8g2.sleepMs(5000);
u8g2.setPowerSave(1);
u8g2.doneI2c();
u8g2.doneUserData();
u8g2.begin();
u8g2.setFont(u8g2_font_6x13_tr); // choose a suitable font
u8g2.drawStr(1, 18, "U8g2 on HW I2C"); // write something to the internal memory
u8g2.sendBuffer(); // transfer internal memory to the display
u8g2.setFont(u8g2_font_unifont_t_symbols);
u8g2.drawGlyph(112, 56, 0x2603);
u8g2.sendBuffer();
u8g2.sleepMs(5000);
u8g2.setPowerSave(1);
u8g2.doneI2c();
u8g2.doneUserData();
}

View File

@ -4,25 +4,26 @@
#define GPIO_CHIP_NUM 0
#define OLED_I2C_PIN_SCL 11
#define OLED_I2C_PIN_SDA 12
#define OLED_I2C_PIN_RESET U8X8_PIN_NONE
// Check https://github.com/olikraus/u8g2/wiki/u8g2setupcpp for all supported devices
static U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0,
/* clock=*/ OLED_I2C_PIN_SCL,
/* data=*/ OLED_I2C_PIN_SDA,
/* reset=*/ U8X8_PIN_NONE);
// All Boards without Reset of the Display
/* clock=*/OLED_I2C_PIN_SCL,
/* data=*/OLED_I2C_PIN_SDA,
/* reset=*/U8X8_PIN_NONE);
// All Boards without Reset of the Display
int main(void)
{
u8g2.initI2cSw(GPIO_CHIP_NUM, OLED_I2C_PIN_SCL, OLED_I2C_PIN_SDA, 0);
u8g2.begin();
u8g2.setFont(u8g2_font_6x13_tr); // choose a suitable font
u8g2.drawStr(1, 18, "U8g2 on SW I2C"); // write something to the internal memory
u8g2.sendBuffer(); // transfer internal memory to the display
u8g2.setFont(u8g2_font_unifont_t_symbols);
u8g2.drawGlyph(112, 56, 0x2603 );
u8g2.sendBuffer();
u8g2.sleepMs(5000);
u8g2.setPowerSave(1);
u8g2.doneUserData();
int main(void) {
u8g2.initI2cSw(GPIO_CHIP_NUM, OLED_I2C_PIN_SCL, OLED_I2C_PIN_SDA,
OLED_I2C_PIN_RESET, 0);
u8g2.begin();
u8g2.setFont(u8g2_font_6x13_tr); // choose a suitable font
u8g2.drawStr(1, 18, "U8g2 on SW I2C"); // write something to the internal memory
u8g2.sendBuffer(); // transfer internal memory to the display
u8g2.setFont(u8g2_font_unifont_t_symbols);
u8g2.drawGlyph(112, 56, 0x2603);
u8g2.sendBuffer();
u8g2.sleepMs(5000);
u8g2.setPowerSave(1);
u8g2.doneUserData();
}

View File

@ -137,11 +137,11 @@ public:
init_i2c_hw(&u8g2, bus);
}
void initI2cSw(uint8_t gpio_chip, uint8_t scl, uint8_t sda,
unsigned long delay) {
init_i2c_sw(&u8g2, gpio_chip, scl, sda, delay);
uint8_t res, unsigned long delay) {
init_i2c_sw(&u8g2, gpio_chip, scl, sda, res, delay);
}
void initSpiHw(uint8_t gpio_chip, uint8_t bus, uint8_t dc, uint8_t res) {
init_spi_hw(&u8g2, gpio_chip, bus, dc, res);
void initSpiHw(uint8_t gpio_chip, uint8_t bus, uint8_t dc, uint8_t res, uint8_t cs) {
init_spi_hw(&u8g2, gpio_chip, bus, dc, res, cs);
}
void initSpiSw(uint8_t gpio_chip, uint8_t dc, uint8_t res,
uint8_t mosi, uint8_t sck, uint8_t cs, unsigned long delay) {

View File

@ -45,7 +45,7 @@ void sleep_ns(unsigned long nanoseconds) {
/*
* Allocate user_data_struct, set common values and set user_ptr.
*/
user_data_t *init_user_data(u8g2_t *u8g2) {
user_data_t* init_user_data(u8g2_t *u8g2) {
// Dynamically allocate u8x8_buffer_struct
user_data_t *user_data = (user_data_t*) malloc(sizeof(user_data_t));
for (int i = 0; i < U8X8_PIN_CNT; ++i) {
@ -67,12 +67,12 @@ void init_i2c_hw(u8g2_t *u8g2, uint8_t bus) {
* Allocate user_data_struct for I2C software.
*/
void init_i2c_sw(u8g2_t *u8g2, uint8_t gpio_chip, uint8_t scl, uint8_t sda,
unsigned long delay) {
uint8_t res, unsigned long delay) {
user_data_t *user_data = init_user_data(u8g2);
user_data->gpio_chip = gpio_chip;
u8x8_SetPin(u8g2_GetU8x8(u8g2), U8X8_PIN_I2C_CLOCK, scl);
u8x8_SetPin(u8g2_GetU8x8(u8g2), U8X8_PIN_I2C_DATA, sda);
u8x8_SetPin(u8g2_GetU8x8(u8g2), U8X8_PIN_RESET, U8X8_PIN_NONE);
u8x8_SetPin(u8g2_GetU8x8(u8g2), U8X8_PIN_RESET, res);
user_data->delay = delay;
}
@ -80,13 +80,13 @@ void init_i2c_sw(u8g2_t *u8g2, uint8_t gpio_chip, uint8_t scl, uint8_t sda,
* Allocate user_data_struct for hardware SPI.
*/
void init_spi_hw(u8g2_t *u8g2, uint8_t gpio_chip, uint8_t bus, uint8_t dc,
uint8_t res) {
uint8_t res, uint8_t cs) {
user_data_t *user_data = init_user_data(u8g2);
user_data->gpio_chip = gpio_chip;
user_data->bus = bus;
u8x8_SetPin(u8g2_GetU8x8(u8g2), U8X8_PIN_DC, dc);
u8x8_SetPin(u8g2_GetU8x8(u8g2), U8X8_PIN_RESET, res);
u8x8_SetPin(u8g2_GetU8x8(u8g2), U8X8_PIN_CS, U8X8_PIN_NONE);
u8x8_SetPin(u8g2_GetU8x8(u8g2), U8X8_PIN_CS, cs);
}
/*

View File

@ -42,9 +42,9 @@ void sleep_ns(unsigned long nanoseconds);
user_data_t *init_user_data(u8g2_t *u8g2);
void init_i2c_hw(u8g2_t *u8g2, uint8_t bus);
void init_i2c_sw(u8g2_t *u8g2, uint8_t gpio_chip, uint8_t scl, uint8_t sda,
unsigned long delay);
uint8_t res, unsigned long delay);
void init_spi_hw(u8g2_t *u8g2, uint8_t gpio_chip, uint8_t bus, uint8_t dc,
uint8_t res);
uint8_t res, uint8_t cs);
void init_spi_sw(u8g2_t *u8g2, uint8_t gpio_chip, uint8_t dc, uint8_t res,
uint8_t mosi, uint8_t sck, uint8_t cs, unsigned long delay);
void done_user_data(u8g2_t *u8g2);