1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/pkg/devices/lib/spi/include/spi-hybrid.h Thu Nov 09 18:40:31 2023 +0100
1.3 @@ -0,0 +1,87 @@
1.4 +/*
1.5 + * Perform SPI communication using a suitable abstraction augmented with
1.6 + * explicit manipulation of a control signal.
1.7 + *
1.8 + * Copyright (C) 2023 Paul Boddie <paul@boddie.org.uk>
1.9 + *
1.10 + * This program is free software; you can redistribute it and/or
1.11 + * modify it under the terms of the GNU General Public License as
1.12 + * published by the Free Software Foundation; either version 2 of
1.13 + * the License, or (at your option) any later version.
1.14 + *
1.15 + * This program is distributed in the hope that it will be useful,
1.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.18 + * GNU General Public License for more details.
1.19 + *
1.20 + * You should have received a copy of the GNU General Public License
1.21 + * along with this program; if not, write to the Free Software
1.22 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
1.23 + * Boston, MA 02110-1301, USA
1.24 + */
1.25 +
1.26 +#pragma once
1.27 +
1.28 +#include <stdint.h>
1.29 +
1.30 +
1.31 +
1.32 +#ifdef __cplusplus
1.33 +
1.34 +#include <l4/devices/gpio.h>
1.35 +#include <l4/devices/spi.h>
1.36 +
1.37 +/* SPI channel abstraction. */
1.38 +
1.39 +class Spi_hybrid : public Spi_channel_base, public Spi_control_base
1.40 +{
1.41 + Spi_channel_base *_channel;
1.42 + Hw::Gpio_chip *_control_device;
1.43 + int _control_pin;
1.44 + int _control_alt_func;
1.45 +
1.46 +public:
1.47 + explicit Spi_hybrid(Spi_channel_base *channel,
1.48 + Hw::Gpio_chip *control_device, int control_pin,
1.49 + int control_alt_func = -1);
1.50 +
1.51 + Spi_channel_base *get_channel();
1.52 +
1.53 + void acquire_control(bool asserted);
1.54 +
1.55 + void release_control();
1.56 +
1.57 + uint32_t send(uint32_t bytes, const uint8_t data[]);
1.58 +
1.59 + uint32_t send_dc(uint32_t bytes, const uint8_t data[], const int dc[]);
1.60 +
1.61 + uint32_t send_units(uint32_t bytes, const uint8_t data[],
1.62 + uint8_t unit_size, uint8_t char_size);
1.63 +};
1.64 +
1.65 +#endif /* __cplusplus */
1.66 +
1.67 +
1.68 +
1.69 +/* C language interface. */
1.70 +
1.71 +EXTERN_C_BEGIN
1.72 +
1.73 +void *spi_hybrid_get_channel(void *channel, void *control_chip, int control_pin,
1.74 + int control_alt_func);
1.75 +
1.76 +void *spi_hybrid_get_raw_channel(void *channel);
1.77 +
1.78 +void spi_hybrid_acquire_control(void *channel, int asserted);
1.79 +
1.80 +void spi_hybrid_release_control(void *channel);
1.81 +
1.82 +uint32_t spi_hybrid_send(void *channel, uint32_t bytes, const uint8_t data[]);
1.83 +
1.84 +uint32_t spi_hybrid_send_dc(void *channel, uint32_t bytes, const uint8_t data[],
1.85 + const int dc[]);
1.86 +
1.87 +uint32_t spi_hybrid_send_units(void *channel, uint32_t bytes, const uint8_t data[],
1.88 + uint8_t unit_size, uint8_t char_size);
1.89 +
1.90 +EXTERN_C_END