pico-ice
RaspberryPi Pico with an iCE40 FPGA
Loading...
Searching...
No Matches
ice_spi.h
1/*
2 * MIT License
3 *
4 * Copyright (c) 2023 tinyVision.ai
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
35#pragma once
36#include <stdint.h>
37#include <stddef.h>
38#include <stdbool.h>
39
45#define ICE_SPI_BAUDRATE (33 * 1000 * 1000)
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
57void ice_spi_init(void);
58
59void ice_spi_init_cs_pin(uint8_t cs_pin, bool active_high);
60
69void ice_spi_chip_select(uint8_t cs_pin);
70
77void ice_spi_chip_deselect(uint8_t csn_pin);
78
88void ice_spi_write_async(const uint8_t *data, size_t data_size, void (*callback)(volatile void *), void *context);
89
95void ice_spi_write_blocking(const uint8_t *data, size_t data_size);
96
108void ice_spi_read_async(uint8_t *data, size_t data_size, void (*callback)(volatile void *), void *context);
109
116void ice_spi_read_blocking(uint8_t *data, size_t data_size);
117
123
128
129#ifdef __cplusplus
130}
131#endif
132
void ice_spi_read_blocking(uint8_t *data, size_t data_size)
Blocking version of ice_spi_read_async().
bool ice_spi_is_async_complete(void)
Checks for compmletion of the current async operation.
void ice_spi_read_async(uint8_t *data, size_t data_size, void(*callback)(volatile void *), void *context)
Wait previous transfer completion if any and enqueue a new one in the background (interrupt-driven).
void ice_spi_write_blocking(const uint8_t *data, size_t data_size)
Blocking version of ice_spi_write_async().
void ice_spi_write_async(const uint8_t *data, size_t data_size, void(*callback)(volatile void *), void *context)
Wait previous transfer completion if any and enqueue a new one in the background (interrupt-driven).
void ice_spi_init(void)
Configure the GPIO pins of the SPI library to high-impedance.
void ice_spi_chip_select(uint8_t cs_pin)
Sets the SPI chip select pin to low state.
void ice_spi_wait_completion(void)
Waits until SPI transfer commpletes.
void ice_spi_chip_deselect(uint8_t csn_pin)
Sets the SPI chip select pin to high state.