25 #if defined(__MINGW32__) 38 #if !defined(SDL_EMULATION) 42 #include <sys/ioctl.h> 43 #include <linux/i2c-dev.h> 45 #include <linux/spi/spidev.h> 52 #if defined(CONFIG_PLATFORM_I2C_AVAILABLE) && defined(CONFIG_PLATFORM_I2C_ENABLE) 54 #if !defined(SDL_EMULATION) 58 static uint8_t s_buffer[128];
59 static uint8_t s_dataSize = 0;
61 static void platform_i2c_start(
void)
66 static void platform_i2c_stop(
void)
68 if (write(s_fd, s_buffer, s_dataSize) != s_dataSize)
70 fprintf(stderr,
"Failed to write to the i2c bus: %s.\n", strerror(errno));
75 static void platform_i2c_send(uint8_t data)
77 s_buffer[s_dataSize] = data;
79 if (s_dataSize ==
sizeof(s_buffer))
89 static void platform_i2c_send_buffer(
const uint8_t *buffer, uint16_t size)
93 platform_i2c_send(*buffer);
98 static void platform_i2c_close()
107 static void empty_function()
111 static void empty_function_single_arg(uint8_t arg)
115 static void empty_function_two_args(
const uint8_t *arg1, uint16_t arg2)
126 snprintf(filename, 19,
"/dev/i2c-%d", busId);
132 if ((s_fd = open(filename, O_RDWR)) < 0)
134 fprintf(stderr,
"Failed to open the i2c bus\n");
141 if (ioctl(s_fd, I2C_SLAVE, s_sa) < 0)
143 fprintf(stderr,
"Failed to acquire bus access and/or talk to slave.\n");
155 #include "sdl_core.h" 157 static void platform_i2c_send_buffer(
const uint8_t *buffer, uint16_t size)
161 sdl_send_byte(*buffer);
179 #endif // CONFIG_PLATFORM_I2C_AVAILABLE 185 #if defined(CONFIG_PLATFORM_SPI_AVAILABLE) && defined(CONFIG_PLATFORM_SPI_ENABLE) 187 #if !defined(SDL_EMULATION) 189 static int s_spi_fd = -1;
192 static void platform_spi_start(
void)
196 static void platform_spi_stop(
void)
200 static void platform_spi_send(uint8_t data)
206 struct spi_ioc_transfer mesg;
208 memset(&mesg, 0,
sizeof mesg);
209 mesg.tx_buf = (
unsigned long)&buf[0];
212 mesg.delay_usecs = 0;
214 mesg.bits_per_word = 8;
216 if (ioctl(s_spi_fd, SPI_IOC_MESSAGE(1), &mesg) < 1)
218 fprintf(stderr,
"SPI failed to send SPI message: %s\n", strerror (errno)) ;
222 static void platform_spi_close(
void)
231 static void platform_spi_send_buffer(
const uint8_t *data, uint16_t len)
235 platform_spi_send(*data);
240 static void empty_function_spi(
void)
244 static void empty_function_arg_spi(uint8_t byte)
248 static void empty_function_args_spi(
const uint8_t *buffer, uint16_t bytes)
274 snprintf(filename, 19,
"/dev/spidev%d.%d", busId, ces);
275 if ((s_spi_fd = open(filename, O_RDWR)) < 0)
277 printf(
"Failed to initialize SPI: %s!\n", strerror(errno));
281 if (ioctl(s_spi_fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed) < 0)
283 printf(
"Failed to set speed on SPI line: %s!\n", strerror(errno));
285 uint8_t mode = SPI_MODE_0;
286 if (ioctl (s_spi_fd, SPI_IOC_WR_MODE, &mode) < 0)
288 printf(
"Failed to set SPI mode: %s!\n", strerror(errno));
291 if (ioctl (s_spi_fd, SPI_IOC_WR_BITS_PER_WORD, &spi_bpw) < 0)
293 printf(
"Failed to set SPI BPW: %s!\n", strerror(errno));
306 #include "sdl_core.h" 308 static void sdl_send_bytes(
const uint8_t *buffer, uint16_t size)
312 sdl_send_byte(*buffer);
328 sdl_set_dc_pin(dcPin);
339 #endif // CONFIG_PLATFORM_SPI_AVAILABLE 341 #endif // __MINGW32__
void ssd1306_platform_spiInit(int8_t busId, int8_t cesPin, int8_t dcPin)
Initializes spi interface for platform being used.
void(* send)(uint8_t data)
uint32_t s_ssd1306_spi_clock
void ssd1306_platform_i2cInit(int8_t busId, uint8_t addr, ssd1306_platform_i2cConfig_t *cfg)
Initializes i2c interface for platform being used.
void(* close)(void)
deinitializes internal resources, allocated for interface.
ssd1306_interface_t ssd1306_intf
void(* send_buffer)(const uint8_t *buffer, uint16_t size)
Sends bytes to SSD1306 device.