Merge pull request #1697 from sgjava/master
Added spi_mode and max_speed to user data
This commit is contained in:
commit
42d2918c0f
|
@ -10,6 +10,7 @@
|
|||
// 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
|
||||
|
||||
|
||||
int main(void) {
|
||||
u8g2_t u8g2;
|
||||
|
||||
|
|
|
@ -136,15 +136,20 @@ 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) {
|
||||
void initSpiHwAdvanced(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_advanced(&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) {
|
||||
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) {
|
||||
|
|
|
@ -76,17 +76,27 @@ void init_i2c_sw(u8g2_t *u8g2, uint8_t gpio_chip, uint8_t scl, uint8_t sda,
|
|||
user_data->delay = delay;
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate user_data_struct for hardware SPI advanced.
|
||||
*/
|
||||
void init_spi_hw_advanced(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;
|
||||
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);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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) {
|
||||
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, cs);
|
||||
init_spi_hw_advanced(u8g2, gpio_chip, bus, dc, res, cs, 0, 500000);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -219,7 +229,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;
|
||||
|
@ -43,6 +47,8 @@ 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_advanced(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,
|
||||
|
|
Loading…
Reference in New Issue