uC chip interface arduino  0.9.0
A interface for async and neuromrphic IC testing
Loading...
Searching...
No Matches
interface_spi.h
Go to the documentation of this file.
1/*
2 This file is part of the Firmware project to interface with small Async or Neuromorphic chips
3 Copyright (C) 2022-2023 Ole Richter - University of Groningen
4 Copyright (C) 2022 Benjamin Hucko
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (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, see <https://www.gnu.org/licenses/>.
18*/
19
20#ifndef INTERFACE_SPI_H
21#define INTERFACE_SPI_H
22#include <cstdint>
23#include <Arduino.h>
24#include "core_ring_buffer.h"
25#include "interface_pin.h"
26#include <SPI.h>
27
29 /*
30
31 */
32
33 public:
34 /*
35 the configure class method handles incomming configuration packets, and also instatiactes the class on activation
36 requires:
37 id - the id of the interface the config is intended for
38 config - the config sub header that determines what is configured
39 data - the associated data to the configuration (if required by the config otherwise ignored)
40 */
41 static void configure(uint8_t id, uint8_t config_option, uint8_t data);
42
43 /*
44 the static configuration stoarge for the interfaces,
45 as the configuration is send in packets that can appear in random order or be incomplete
46 they are stored staticly in the class untill the interface is activated
47 */
48 static volatile uint8_t width[SPI_NUMBER_OF_INTERFACES];
49 static volatile uint32_t frequency[SPI_NUMBER_OF_INTERFACES];
50 static volatile uint8_t mode[SPI_NUMBER_OF_INTERFACES];
51 static volatile bool byte_order[SPI_NUMBER_OF_INTERFACES];
52 static volatile bool active[SPI_NUMBER_OF_INTERFACES];
53
54 /*
55 the pointers to the interface instantces after activation.
56 */
58
59 static void send_packet(uint8_t id, uint32_t data);
60
61 //-----------------------------------------------------------------------------------------------------------------------------------
62 // Class constructor;
63 //-----------------------------------------------------------------------------------------------------------------------------------
64 Interface_spi(uint8_t id, uint32_t frequency = 100000U, uint8_t width = 1, uint8_t mode = 0, bool byte_order = false);
65
66
67 //----------------------------------------------------------------------------------------------------------------------------------
68 // number of bytes can be 1-2s
69 //----------------------------------------------------------------------------------------------------------------------------------
70 void write(uint32_t data) volatile;
71
72 // ---------------------------------------------------- Declaring private methods --------------------------------------------------
73 protected:
74
75 uint8_t _id;
76 uint8_t _mode;
77 uint8_t _width;
79 uint32_t _frequency;
80 #if defined(TEENSYDUINO)
81 SPIClass *_spi;
82 #else
83 arduino::SPIClass *_spi;
84 #endif
85
86
87};
88
89
90#endif
static volatile bool byte_order[SPI_NUMBER_OF_INTERFACES]
Definition: interface_spi.h:51
uint32_t _frequency
Definition: interface_spi.h:79
static void send_packet(uint8_t id, uint32_t data)
static void configure(uint8_t id, uint8_t config_option, uint8_t data)
static volatile uint8_t mode[SPI_NUMBER_OF_INTERFACES]
Definition: interface_spi.h:50
arduino::SPIClass * _spi
Definition: interface_spi.h:83
uint8_t _width
Definition: interface_spi.h:77
void write(uint32_t data) volatile
static volatile Interface_spi * inst[SPI_NUMBER_OF_INTERFACES]
Definition: interface_spi.h:57
static volatile uint32_t frequency[SPI_NUMBER_OF_INTERFACES]
Definition: interface_spi.h:49
static volatile bool active[SPI_NUMBER_OF_INTERFACES]
Definition: interface_spi.h:52
static volatile uint8_t width[SPI_NUMBER_OF_INTERFACES]
Definition: interface_spi.h:48
#define SPI_NUMBER_OF_INTERFACES
Definition: uc_boards.h:117