uC chip interface arduino  0.9.0
A interface for async and neuromrphic IC testing
Loading...
Searching...
No Matches
interface_i2c.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) 2023 Ole Richter - University of Groningen
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>.
17*/
18
19#ifndef INTERFACE_I2C_H
20#define INTERFACE_I2C_H
21
22#include <Arduino.h>
23#include <Wire.h>
24#include "core_ring_buffer.h"
25#include "interface_pin.h"
26#include "datatypes.h"
27#include "uc_boards.h"
28
29
31 /*
32
33 */
34
35 public:
36 /*
37 the configure class method handles incomming configuration packets, and also instatiactes the class on activation
38 requires:
39 id - the id of the interface the config is intended for
40 config - the config sub header that determines what is configured
41 data - the associated data to the configuration (if required by the config otherwise ignored)
42 */
43 static void configure(uint8_t id, uint8_t config, uint8_t data);
44
45 /*
46 the static configuration stoarge for the interfaces,
47 as the configuration is send in packets that can appear in random order or be incomplete
48 they are stored staticly in the class untill the interface is activated
49 */
50 static volatile uint8_t width[I2C_NUMBER_OF_INTERFACES];
51 static volatile uint8_t byte_order[I2C_NUMBER_OF_INTERFACES];
52 static volatile bool active[I2C_NUMBER_OF_INTERFACES];
53 static volatile uint32_t frequency[I2C_NUMBER_OF_INTERFACES];
54 /*
55 the pointers to the interface instantces after activation.
56 */
58
59 static void process_packet(uint8_t id,uint8_t device_address, uint8_t register_address, uint8_t data_ms, uint8_t data_ls);
60
61 //-----------------------------------------------------------------------------------------------------------------------------------
62 // Class constructor;
63 //-----------------------------------------------------------------------------------------------------------------------------------
64 Interface_i2c(uint8_t id, uint32_t freqency = 100000U);
65
66
67 //----------------------------------------------------------------------------------------------------------------------------------
68 // number of bytes can be 1-2s
69 //----------------------------------------------------------------------------------------------------------------------------------
70 void write(uint8_t device_address, uint8_t register_address, uint8_t data_ms, uint8_t data_ls) volatile;
71
72 //----------------------------------------------------------------------------------------------------------------------------------
73 // number of bytes can be 1-4
74 //----------------------------------------------------------------------------------------------------------------------------------
75 void read(uint8_t device_address, uint8_t register_address, uint8_t number_of_bytes) volatile;
76 uint16_t read_return(uint8_t device_address, uint8_t register_address) volatile;
77
78 // ---------------------------------------------------- Declaring private methods --------------------------------------------------
79 protected:
80
81 uint8_t _id;
82 uint32_t _frequency;
83 #if defined(TEENSYDUINO)
84 TwoWire* _i2c;
85 #else
86 arduino::TwoWire* _i2c;
87 #endif
88};
89
90#endif
uint32_t _frequency
Definition: interface_i2c.h:82
arduino::TwoWire * _i2c
Definition: interface_i2c.h:86
static volatile uint8_t width[I2C_NUMBER_OF_INTERFACES]
Definition: interface_i2c.h:50
void read(uint8_t device_address, uint8_t register_address, uint8_t number_of_bytes) volatile
uint16_t read_return(uint8_t device_address, uint8_t register_address) volatile
static volatile bool active[I2C_NUMBER_OF_INTERFACES]
Definition: interface_i2c.h:52
static volatile uint8_t byte_order[I2C_NUMBER_OF_INTERFACES]
Definition: interface_i2c.h:51
static void configure(uint8_t id, uint8_t config, uint8_t data)
static volatile Interface_i2c * inst[I2C_NUMBER_OF_INTERFACES]
Definition: interface_i2c.h:57
void write(uint8_t device_address, uint8_t register_address, uint8_t data_ms, uint8_t data_ls) volatile
static void process_packet(uint8_t id, uint8_t device_address, uint8_t register_address, uint8_t data_ms, uint8_t data_ls)
static volatile uint32_t frequency[I2C_NUMBER_OF_INTERFACES]
Definition: interface_i2c.h:53
#define I2C_NUMBER_OF_INTERFACES
Definition: uc_boards.h:112