Modmata  v0
An arduino communications server using Modbus
Functions.h
Go to the documentation of this file.
1 /*
2 Modmata Functions
3 Copyright © 2023 char* teamName <shutche@siue.edu>
4 Licensed under LGPL-2.1
5 */
6 
7 /**
8  * @file Functions.h
9  * @author Sam Hutcherson, Chase Wallendorff, Iris Astrid
10  * @brief Header file for 'Functions.cpp'
11  * @date 2023-04-06
12  */
13 
14 #include <stdlib.h>
15 #include <stdint.h>
16 #include <Arduino.h>
17 #include <Servo.h>
18 #include <Wire.h>
19 #include <SPI.h>
20 
21 #ifndef FUNCTIONS_H
22 #define FUNCTIONS_H
23 
24 /**
25  * @brief Combine four 8-bit integral types into one 32-bit integral type,
26  * or in simpler terms, reassemble a uint32_t from four uint8_t's
27  */
28 #define makeDWord(i0, i1, i2, i3) ((uint32_t) (i0 << 24 | i1 << 16 | i2 << 8 | i3))
29 
30 // Command number associated with each function
31 
32 #define IDLE 0
33 #define PINMODE 1
34 #define DIGITALWRITE 2
35 #define DIGITALREAD 3
36 #define ANALOGREFERENCE 4
37 #define ANALOGWRITE 5
38 #define ANALOGREAD 6
39 #define SERVOATTACH 7
40 #define SERVODETACH 8
41 #define SERVOWRITE 9
42 #define SERVOREAD 10
43 #define WIREBEGIN 11
44 #define WIREEND 12
45 #define WIRECLOCK 13
46 #define WIREWRITE 14
47 #define WIREREAD 15
48 #define SPIBEGIN 16
49 #define SPISETTINGS 17
50 #define SPITRANSFER 18
51 #define SPIEND 19
52 
53 /**
54  * @brief A data structure to describe function arguments and return values.
55  * @param count The number of arguments contained within the array 'value'.
56  * @param value A pointer to an array of bytes (8-bit integral types) that
57  * contains the values of the arguments or return values for a command.
58  */
59 struct registers {
60  /** The number of arguments contained within the array 'value'. */
61  uint8_t count;
62 
63  /** A pointer to an array of bytes (8-bit integral types) that contains the values of the arguments or return values for a command. */
64  uint8_t * value;
65 };
66 
67 /**
68  * @brief A data structure to describe a SPI connection's configuration settings.
69  * Essentially the same as Arduino's 'SPIsettings' object
70  * @param speed The baud rate/clock speed of the connection.
71  * @param order The order of bits sent over the wire
72  * @param mode The clock polarity and phase
73  */
74 struct spi_settings {
75  /** The baud rate/clock speed of the connection. */
76  uint32_t speed;
77 
78  /** The order of bits sent over the wire. */
79  bool order;
80 
81  /** The clock polarity and phase. */
82  uint8_t mode;
83 };
84 
85 
86 // General Arduino functions
87 
88 struct registers pinMode(uint8_t argc, uint8_t *argv);
89 struct registers digitalWrite(uint8_t argc, uint8_t *argv);
90 struct registers digitalRead(uint8_t argc, uint8_t *argv);
91 struct registers analogWrite(uint8_t argc, uint8_t *argv);
92 struct registers analogRead(uint8_t argc, uint8_t *argv);
93 
94 
95 // Servo functions
96 
97 struct registers servoAttach(uint8_t argc, uint8_t *argv);
98 struct registers servoDetach(uint8_t argc, uint8_t *argv);
99 struct registers servoWrite(uint8_t argc, uint8_t *argv);
100 struct registers servoRead(uint8_t argc, uint8_t *argv);
101 
102 
103 // I2C functions
104 
105 struct registers wireBegin(uint8_t argc, uint8_t *argv);
106 struct registers wireEnd(uint8_t argc, uint8_t *argv);
107 struct registers wireSetClock(uint8_t argc, uint8_t *argv);
108 struct registers wireWrite(uint8_t argc, uint8_t *argv);
109 struct registers wireRead(uint8_t argc, uint8_t *argv);
110 
111 
112 // SPI functions
113 
114 struct registers spiBegin(uint8_t argc, uint8_t *argv);
115 struct registers spiSettings(uint8_t argc, uint8_t *argv);
116 struct registers spiTransferBuf(uint8_t argc, uint8_t *argv);
117 struct registers spiEnd(uint8_t argc, uint8_t *argv);
118 
119 #endif
struct registers pinMode(uint8_t argc, uint8_t *argv)
Change the settings of the Arduino I/O pins.
Definition: Functions.cpp:38
uint8_t mode
Definition: Functions.h:82
struct registers spiSettings(uint8_t argc, uint8_t *argv)
Change the settings of the SPI connection.
Definition: Functions.cpp:331
uint8_t * value
Definition: Functions.h:64
struct registers wireSetClock(uint8_t argc, uint8_t *argv)
Change the clock speed settings of the I2C connection.
Definition: Functions.cpp:239
struct registers wireRead(uint8_t argc, uint8_t *argv)
Read data from the connected I2C peripheral.
Definition: Functions.cpp:280
struct registers servoRead(uint8_t argc, uint8_t *argv)
Read a value from the connected servo.
Definition: Functions.cpp:194
struct registers wireWrite(uint8_t argc, uint8_t *argv)
Write data to the connected I2C peripheral.
Definition: Functions.cpp:256
struct registers wireEnd(uint8_t argc, uint8_t *argv)
End an I2C connection between the Arduino and a peripheral.
Definition: Functions.cpp:227
bool order
Definition: Functions.h:79
struct registers spiBegin(uint8_t argc, uint8_t *argv)
Begin a SPI connection between the Arduino and a peripheral.
Definition: Functions.cpp:313
struct registers analogWrite(uint8_t argc, uint8_t *argv)
Write an analog value (0-255) to the Arduino I/O pins.
Definition: Functions.cpp:88
struct registers servoWrite(uint8_t argc, uint8_t *argv)
Write a value to the connected servo.
Definition: Functions.cpp:170
struct registers servoDetach(uint8_t argc, uint8_t *argv)
Detach a servo from the the control interface.
Definition: Functions.cpp:147
struct registers servoAttach(uint8_t argc, uint8_t *argv)
Attach a connected servo to a control interface.
Definition: Functions.cpp:124
struct registers analogRead(uint8_t argc, uint8_t *argv)
Read an analog value (0-1023) from the Arduino I/O pins.
Definition: Functions.cpp:103
uint8_t count
Definition: Functions.h:61
uint32_t speed
Definition: Functions.h:76
struct registers digitalRead(uint8_t argc, uint8_t *argv)
Read a digital value (HIGH/LOW) from the Arduino I/O pins.
Definition: Functions.cpp:68
struct registers spiTransferBuf(uint8_t argc, uint8_t *argv)
Exchange data over the SPI connection (Read + Write)
Definition: Functions.cpp:349
struct registers digitalWrite(uint8_t argc, uint8_t *argv)
Write a digital (HIGH/LOW) value to the Arduino I/O pins.
Definition: Functions.cpp:53
struct registers spiEnd(uint8_t argc, uint8_t *argv)
End a SPI connection between the Arduino and a peripheral.
Definition: Functions.cpp:381
struct registers wireBegin(uint8_t argc, uint8_t *argv)
Begin an I2C connection between the Arduino and a peripheral.
Definition: Functions.cpp:215
A data structure to describe function arguments and return values.
Definition: Functions.h:59
A data structure to describe a SPI connection's configuration settings. Essentially the same as Ardui...
Definition: Functions.h:74