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 <stdint.h> 25 26 27 28 #ifdef __cplusplus 29 30 #include <l4/devices/gpio.h> 31 #include <l4/devices/spi.h> 32 33 /* SPI channel abstraction. */ 34 35 class Spi_gpio : public Spi_channel_base 36 { 37 uint64_t _frequency; 38 Hw::Gpio_chip *_clock_device; 39 int _clock_pin; 40 Hw::Gpio_chip *_data_device; 41 int _data_pin; 42 Hw::Gpio_chip *_enable_device; 43 int _enable_pin; 44 Hw::Gpio_chip *_control_device; 45 int _control_pin; 46 47 public: 48 explicit Spi_gpio(uint64_t frequency, 49 Hw::Gpio_chip *clock_device, int clock_pin, 50 Hw::Gpio_chip *data_device, int data_pin, 51 Hw::Gpio_chip *enable_device, int enable_pin, 52 Hw::Gpio_chip *control_device = NULL, int control_pin = 0); 53 54 explicit Spi_gpio(Hw::Gpio_chip *clock_device, int clock_pin, 55 Hw::Gpio_chip *data_device, int data_pin, 56 Hw::Gpio_chip *enable_device, int enable_pin, 57 Hw::Gpio_chip *control_device = NULL, int control_pin = 0); 58 59 uint32_t send(uint32_t bytes, const uint8_t data[]); 60 61 uint32_t send_dc(uint32_t bytes, const uint8_t data[], const int dc[]); 62 63 uint32_t send_units(uint32_t bytes, const uint8_t data[], uint8_t unit_size, 64 uint8_t char_size); 65 }; 66 67 #endif /* __cplusplus */ 68 69 70 71 /* C language interface. */ 72 73 EXTERN_C_BEGIN 74 75 void *spi_gpio_get_channel(uint64_t frequency, 76 void *clock_chip, int clock_pin, 77 void *data_chip, int data_pin, 78 void *enable_chip, int enable_pin, 79 void *control_chip, int control_pin); 80 81 uint32_t spi_gpio_send(void *channel, uint32_t bytes, const uint8_t data[]); 82 83 uint32_t spi_gpio_send_dc(void *channel, uint32_t bytes, const uint8_t data[], 84 const int dc[]); 85 86 uint32_t spi_gpio_send_units(void *channel, uint32_t bytes, const uint8_t data[], 87 uint8_t unit_size, uint8_t char_size); 88 89 EXTERN_C_END