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 #pragma once 23 24 #include <l4/devices/gpio.h> 25 #include <stdint.h> 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 uint64_t _frequency; 42 43 public: 44 explicit Spi_gpio(Hw::Gpio_chip *clock_device, int clock_pin, 45 Hw::Gpio_chip *data_device, int data_pin, 46 Hw::Gpio_chip *enable_device, int enable_pin, 47 uint64_t frequency = 0); 48 49 void send(int bytes, const uint8_t data[]); 50 }; 51 52 #endif /* __cplusplus */ 53 54 55 56 /* C language interface. */ 57 58 EXTERN_C_BEGIN 59 60 void *spi_gpio_get_channel(void *clock_chip, int clock_pin, 61 void *data_chip, int data_pin, 62 void *enable_chip, int enable_pin, 63 uint64_t frequency); 64 65 void spi_gpio_send(void *channel, int bytes, const uint8_t data[]); 66 67 EXTERN_C_END