Refactor to add init_spi_hw_advance

This commit is contained in:
servadmin 2021-11-18 07:57:40 -05:00
parent bffa798ad5
commit 109c704d33
5 changed files with 21 additions and 11 deletions

View File

@ -9,8 +9,6 @@
// CS pin is controlled by linux spi driver, thus not defined here, but need to be wired
#define OLED_SPI_PIN_CS U8X8_PIN_NONE
#define SPI_MODE 0
#define SPI_MAX_SPEED 500000
int main(void) {
@ -20,7 +18,7 @@ int main(void) {
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, OLED_SPI_PIN_CS, SPI_MODE, SPI_MAX_SPEED);
OLED_SPI_PIN_RES, OLED_SPI_PIN_CS);
u8g2_InitDisplay(&u8g2);
u8g2_ClearBuffer(&u8g2);

View File

@ -6,8 +6,6 @@
#define SPI_BUS 0x10
#define OLED_SPI_PIN_RES 199
#define OLED_SPI_PIN_DC 198
#define SPI_MODE 0
#define SPI_MAX_SPEED 500000
// CS pin is controlled by linux spi driver
#define OLED_SPI_PIN_CS U8X8_PIN_NONE
@ -21,7 +19,7 @@ static U8G2_SSD1306_128X64_NONAME_F_4W_HW_SPI u8g2(U8G2_R0,
int main() {
u8g2.initSpiHw(GPIO_CHIP_NUM, SPI_BUS, OLED_SPI_PIN_DC, OLED_SPI_PIN_RES,
OLED_SPI_PIN_CS, SPI_MODE, SPI_MAX_SPEED);
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

@ -140,9 +140,13 @@ public:
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,
void initSpiHwAdvance(uint8_t gpio_chip, uint8_t bus, uint8_t dc, uint8_t res,
uint8_t cs, unsigned int spi_mode, uint32_t max_speed) {
init_spi_hw(&u8g2, gpio_chip, bus, dc, res, cs, spi_mode, max_speed);
init_spi_hw_advance(&u8g2, gpio_chip, bus, dc, res, cs, spi_mode, max_speed);
}
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

@ -77,9 +77,9 @@ void init_i2c_sw(u8g2_t *u8g2, uint8_t gpio_chip, uint8_t scl, uint8_t sda,
}
/*
* Allocate user_data_struct for hardware SPI.
* Allocate user_data_struct for hardware SPI advanced.
*/
void init_spi_hw(u8g2_t *u8g2, uint8_t gpio_chip, uint8_t bus, uint8_t dc,
void init_spi_hw_advance(u8g2_t *u8g2, uint8_t gpio_chip, uint8_t bus, uint8_t dc,
uint8_t res, uint8_t cs, unsigned int spi_mode, uint32_t max_speed) {
user_data_t *user_data = init_user_data(u8g2);
user_data->gpio_chip = gpio_chip;
@ -91,6 +91,14 @@ void init_spi_hw(u8g2_t *u8g2, uint8_t gpio_chip, uint8_t bus, uint8_t dc,
u8x8_SetPin(u8g2_GetU8x8(u8g2), U8X8_PIN_CS, cs);
}
/*
* 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 cs) {
init_spi_hw_advance(u8g2, gpio_chip, bus, dc, res, cs, 0, 500000);
}
/*
* Allocate user_data_struct for hardware SPI.
*/

View File

@ -47,8 +47,10 @@ 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,
uint8_t res, unsigned long delay);
void init_spi_hw(u8g2_t *u8g2, uint8_t gpio_chip, uint8_t bus, uint8_t dc,
void init_spi_hw_advance(u8g2_t *u8g2, uint8_t gpio_chip, uint8_t bus, uint8_t dc,
uint8_t res, uint8_t cs, unsigned int spi_mode, uint32_t max_speed);
void init_spi_hw(u8g2_t *u8g2, uint8_t gpio_chip, uint8_t bus, uint8_t dc,
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);