1 /* 2 * Perform SPI communication using GPIO operations. 3 * 4 * Copyright (C) 2018, 2020, 2023 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #include <l4/devices/gpio.h> 23 #include <stdint.h> 24 25 #pragma once 26 27 28 29 #ifdef __cplusplus 30 31 /* SPI peripheral device. */ 32 33 class Spi_gpio 34 { 35 Hw::Gpio_chip *_clock_device; 36 int _clock_pin; 37 Hw::Gpio_chip *_data_device; 38 int _data_pin; 39 Hw::Gpio_chip *_enable_device; 40 int _enable_pin; 41 uint32_t _frequency; 42 43 public: 44 /* Associate the device with a particular memory region. */ 45 46 explicit Spi_gpio(Hw::Gpio_chip *clock_device, int clock_pin, 47 Hw::Gpio_chip *data_device, int data_pin, 48 Hw::Gpio_chip *enable_device, int enable_pin, 49 uint32_t frequency = 0); 50 51 void send(int bytes, const uint8_t data[]); 52 }; 53 54 #endif /* __cplusplus */ 55 56 57 58 /* C language interface. */ 59 60 EXTERN_C_BEGIN 61 62 void *spi_gpio_get_channel(void *clock_chip, int clock_pin, 63 void *data_chip, int data_pin, 64 void *enable_chip, int enable_pin, 65 uint32_t frequency); 66 67 void spi_gpio_send(void *channel, int bytes, const uint8_t data[]); 68 69 EXTERN_C_END