libnile
Loading...
Searching...
No Matches
spi.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023, 2024, 2025 Adrian "asie" Siekierka
3 *
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 *
8 * Permission is granted to anyone to use this software for any purpose,
9 * including commercial applications, and to alter it and redistribute it
10 * freely, subject to the following restrictions:
11 *
12 * 1. The origin of this software must not be misrepresented; you must not
13 * claim that you wrote the original software. If you use this software
14 * in a product, an acknowledgment in the product documentation would be
15 * appreciated but is not required.
16 *
17 * 2. Altered source versions must be plainly marked as such, and must not be
18 * misrepresented as being the original software.
19 *
20 * 3. This notice may not be removed or altered from any source distribution.
21 */
22
23#ifndef NILE_SPI_H_
24#define NILE_SPI_H_
25
26#include <wonderful.h>
27#include "hardware.h"
28
29#ifndef __ASSEMBLER__
30#include <stdbool.h>
31#include <stdint.h>
32
36uint16_t nile_spi_get_timeout(void);
37
41void nile_spi_set_timeout(uint16_t ms);
42
52
59bool nile_spi_abort(void);
60
66
75
81bool nile_spi_set_device(uint16_t device);
82
86bool nile_spi_set_control(uint16_t value);
87
91static inline void nile_spi_flip_buffer(void) {
92 outportb(IO_NILE_SPI_CNT + 1, inportb(IO_NILE_SPI_CNT + 1) ^ (NILE_SPI_BUFFER_IDX >> 8));
93}
94
103bool nile_spi_rx_async(uint16_t size, uint16_t mode);
104
112static inline bool nile_spi_tx_async(uint16_t size) {
114}
115
124bool nile_spi_tx_async_block(const void __far* buf, uint16_t size);
125
134static inline bool nile_spi_tx_sync_block(const void __far* buf, uint16_t size) {
135 return nile_spi_tx_async_block(buf, size) && nile_spi_wait_ready();
136}
137
147bool nile_spi_rx_sync_flip(uint16_t size, uint16_t mode);
148
158bool nile_spi_rx_sync_block(void __far* buf, uint16_t size, uint16_t mode);
159
169bool nile_spi_xch_block(void __far* buf, uint16_t size);
170
178uint16_t nile_spi_xch(uint8_t value);
179#define NILE_SPI_XCH_ERROR_MASK 0xFF00
180
181#endif /* __ASSEMBLER__ */
182
183#endif /* NILE_SPI_H_ */
#define NILE_SPI_BUFFER_IDX
Definition hardware.h:41
#define NILE_SPI_MODE_WRITE
Definition hardware.h:28
#define IO_NILE_SPI_CNT
Definition hardware.h:45
static bool nile_spi_tx_sync_block(const void __far *buf, uint16_t size)
Synchronously transfer block of data over the SPI interface.
Definition spi.h:134
bool nile_spi_wait_ready(void)
Wait until the SPI interface is ready. The maximum number of milliseconds for the wait is set using n...
bool nile_spi_set_speed(nile_spi_speed_t speed)
Safely set the speed used by the SPI controller.
void nile_spi_set_timeout(uint16_t ms)
Set the SPI communication timeout value, in milliseconds.
uint16_t nile_spi_xch(uint8_t value)
Synchronously exchange byte over the SPI interface.
bool nile_spi_set_control(uint16_t value)
Safely configure the control port.
uint16_t nile_spi_get_timeout(void)
Get the SPI communication timeout value, in milliseconds.
static bool nile_spi_tx_async(uint16_t size)
Asynchronously transfer block of data over the SPI interface.
Definition spi.h:112
bool nile_spi_abort(void)
Abort SPI transfer.
static void nile_spi_flip_buffer(void)
Flip the currently accessible SPI buffer.
Definition spi.h:91
bool nile_spi_rx_async(uint16_t size, uint16_t mode)
Asynchronously receive block of data over the SPI interface.
bool nile_spi_rx_sync_flip(uint16_t size, uint16_t mode)
Synchronously receive block of data over the SPI interface and flip the buffer so that it can be acce...
bool nile_spi_xch_block(void __far *buf, uint16_t size)
Synchronously exchange block of data over the SPI interface.
bool nile_spi_tx_async_block(const void __far *buf, uint16_t size)
Asynchronously transfer block of data over the SPI interface.
bool nile_spi_rx_sync_block(void __far *buf, uint16_t size, uint16_t mode)
Synchronously receive block of data over the SPI interface.
bool nile_spi_set_device(uint16_t device)
Safely set the device targetted by the SPI controller.
nile_spi_speed_t
Definition spi.h:61
@ NILE_SPI_SPEED_384KHZ
384 KHz
Definition spi.h:62
@ NILE_SPI_SPEED_24MHZ
24 MHz (increased power draw)
Definition spi.h:64
@ NILE_SPI_SPEED_6MHZ
6 MHz on SPHINX, 384 KHz on ASWAN
Definition spi.h:63