Added spi_mode and max_speed to user data
This commit is contained in:
parent
df7f3b3023
commit
bffa798ad5
|
@ -9,6 +9,9 @@
|
|||
|
||||
// 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) {
|
||||
u8g2_t u8g2;
|
||||
|
@ -17,7 +20,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);
|
||||
OLED_SPI_PIN_RES, OLED_SPI_PIN_CS, SPI_MODE, SPI_MAX_SPEED);
|
||||
|
||||
u8g2_InitDisplay(&u8g2);
|
||||
u8g2_ClearBuffer(&u8g2);
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#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
|
||||
|
@ -19,7 +21,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);
|
||||
OLED_SPI_PIN_CS, SPI_MODE, SPI_MAX_SPEED);
|
||||
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
|
||||
|
|
|
@ -136,15 +136,16 @@ public:
|
|||
void initI2cHw(uint8_t bus) {
|
||||
init_i2c_hw(&u8g2, bus);
|
||||
}
|
||||
void initI2cSw(uint8_t gpio_chip, uint8_t scl, uint8_t sda,
|
||||
uint8_t res, unsigned long delay) {
|
||||
void initI2cSw(uint8_t gpio_chip, uint8_t scl, uint8_t sda, 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, uint8_t cs) {
|
||||
init_spi_hw(&u8g2, gpio_chip, bus, dc, res, cs);
|
||||
void initSpiHw(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);
|
||||
}
|
||||
void initSpiSw(uint8_t gpio_chip, uint8_t dc, uint8_t res,
|
||||
uint8_t mosi, uint8_t sck, uint8_t cs, unsigned long delay) {
|
||||
void initSpiSw(uint8_t gpio_chip, uint8_t dc, uint8_t res, uint8_t mosi,
|
||||
uint8_t sck, uint8_t cs, unsigned long delay) {
|
||||
init_spi_sw(&u8g2, gpio_chip, dc, res, mosi, sck, cs, delay);
|
||||
}
|
||||
void doneUserData(void) {
|
||||
|
|
|
@ -80,10 +80,12 @@ 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 cs) {
|
||||
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;
|
||||
user_data->bus = bus;
|
||||
user_data->spi_mode = spi_mode;
|
||||
user_data->max_speed = max_speed;
|
||||
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, cs);
|
||||
|
@ -219,7 +221,7 @@ void init_spi(u8x8_t *u8x8) {
|
|||
/* 2: clock active low, data out on rising edge */
|
||||
/* 3: clock active low, data out on falling edge */
|
||||
int error = spi_open(spi_handles[user_data->bus], filename,
|
||||
u8x8->display_info->spi_mode, 500000);
|
||||
user_data->spi_mode, user_data->max_speed);
|
||||
if (error < 0) {
|
||||
fprintf(stderr, "spi_open(): %s\n",
|
||||
spi_errmsg(spi_handles[user_data->bus]));
|
||||
|
|
|
@ -32,6 +32,10 @@ struct user_data_struct {
|
|||
uint8_t buffer[128];
|
||||
// Nanosecond delay for U8X8_MSG_DELAY_I2C
|
||||
unsigned long delay;
|
||||
// SPI mode
|
||||
unsigned int spi_mode;
|
||||
// SPI max speed
|
||||
uint32_t max_speed;
|
||||
};
|
||||
|
||||
typedef struct user_data_struct user_data_t;
|
||||
|
@ -44,7 +48,7 @@ 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,
|
||||
uint8_t res, uint8_t cs);
|
||||
uint8_t res, uint8_t cs, unsigned int spi_mode, uint32_t max_speed);
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue