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