SPI3 support
This commit is contained in:
parent
0b063730f3
commit
455fc6f940
3 changed files with 38 additions and 6 deletions
|
|
@ -9,4 +9,8 @@
|
|||
#define SSD1306_SPI4_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#ifndef SSD1306_SPI3_SUPPORT
|
||||
#define SSD1306_SPI3_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#endif /* _EXTRAS_SSD1306_CONFIG_H_ */
|
||||
|
|
|
|||
|
|
@ -118,6 +118,15 @@ int ssd1306_command(const ssd1306_t *dev, uint8_t cmd)
|
|||
spi_transfer_8(SPI_BUS, cmd);
|
||||
gpio_write(dev->cs_pin, true);
|
||||
break;
|
||||
#endif
|
||||
#if (SSD1306_SPI3_SUPPORT)
|
||||
case SSD1306_PROTO_SPI3:
|
||||
gpio_write(dev->cs_pin, false);
|
||||
spi_set_command(SPI_BUS,1,0); // command mode
|
||||
spi_transfer_8(SPI_BUS, cmd);
|
||||
spi_clear_command(SPI_BUS);
|
||||
gpio_write(dev->cs_pin, true);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
debug("Unsupported protocol");
|
||||
|
|
@ -157,6 +166,13 @@ int ssd1306_init(const ssd1306_t *dev)
|
|||
gpio_enable(dev->dc_pin, GPIO_OUTPUT);
|
||||
spi_init(SPI_BUS, SPI_MODE0, SPI_FREQ_DIV_8M, true, SPI_LITTLE_ENDIAN, true);
|
||||
break;
|
||||
#endif
|
||||
#if (SSD1306_SPI3_SUPPORT)
|
||||
case SSD1306_PROTO_SPI3:
|
||||
gpio_enable(dev->cs_pin, GPIO_OUTPUT);
|
||||
gpio_write(dev->cs_pin, true);
|
||||
spi_init(SPI_BUS, SPI_MODE0, SPI_FREQ_DIV_8M, true, SPI_LITTLE_ENDIAN, true);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
debug("Unsupported protocol");
|
||||
|
|
@ -232,9 +248,19 @@ int ssd1306_load_frame_buffer(const ssd1306_t *dev, uint8_t buf[])
|
|||
if (buf)
|
||||
spi_transfer(SPI_BUS, buf, NULL, len, SPI_8BIT);
|
||||
else
|
||||
for (i = 0; i < len; i ++) {
|
||||
spi_transfer_8(SPI_BUS, 0);
|
||||
}
|
||||
spi_repeat_send_8(SPI_BUS,0,len);
|
||||
gpio_write(dev->cs_pin, true);
|
||||
break;
|
||||
#endif
|
||||
#if (SSD1306_SPI3_SUPPORT)
|
||||
case SSD1306_PROTO_SPI3:
|
||||
spi_set_command(SPI_BUS,1,1); // data mode
|
||||
gpio_write(dev->cs_pin, false);
|
||||
if (buf)
|
||||
spi_transfer(SPI_BUS, buf, NULL, len, SPI_8BIT);
|
||||
else
|
||||
spi_repeat_send_8(SPI_BUS,0,len);
|
||||
spi_clear_command(SPI_BUS);
|
||||
gpio_write(dev->cs_pin, true);
|
||||
break;
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ typedef enum
|
|||
{
|
||||
SSD1306_PROTO_I2C = 0, //!< I2C
|
||||
SSD1306_PROTO_SPI4, //!< SPI 8 bits + D/C pin
|
||||
SSD1306_PROTO_SPI3 //!< SPI 9 bits, currently not supported
|
||||
SSD1306_PROTO_SPI3 //!< SPI 9 bits
|
||||
} ssd1306_protocol_t;
|
||||
|
||||
/**
|
||||
|
|
@ -44,11 +44,13 @@ typedef enum
|
|||
typedef struct
|
||||
{
|
||||
ssd1306_protocol_t protocol;
|
||||
union {
|
||||
#if (SSD1306_I2C_SUPPORT)
|
||||
uint8_t addr; //!< I2C address, used by SSD1306_PROTO_I2C
|
||||
uint8_t addr ; //!< I2C address, used by SSD1306_PROTO_I2C
|
||||
#endif
|
||||
uint8_t cs_pin ; //!< Chip Select GPIO pin, used by SSD1306_PROTO_SPI3, SSD1306_PROTO_SPI4
|
||||
} ;
|
||||
#if (SSD1306_SPI4_SUPPORT)
|
||||
uint8_t cs_pin; //!< Chip Select GPIO pin, used by SSD1306_PROTO_SPI3, SSD1306_PROTO_SPI4
|
||||
uint8_t dc_pin; //!< Data/Command GPIO pin, used by SSD1306_PROTO_SPI4
|
||||
#endif
|
||||
uint8_t width; //!< Screen width, currently supported 128px, 96px
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue