-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibrary_functions.cpp
126 lines (112 loc) · 3.82 KB
/
library_functions.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
* Arduino-MX25Series is an Arduino Library for the Macronix MX25-Series flash chips.
* Copyright (C) 2021 eResearch, James Cook University
* Author: NigelB
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* Repository: https://github.com/jcu-eresearch/Arduino-MX25Series
*
*/
#include "MX25Series.h"
#include "ArduinoMX25Series.h"
#include "Arduino.h"
#include "SPI.h"
bool MX25Series___test_linker(MX25Series_t *dev)
{
ArduinoMX25Series *flash = nullptr;
if(dev->ctx != nullptr) {
flash = static_cast<ArduinoMX25Series *>(dev->ctx);
flash->println("MX25Series___test_linker: Successfully Linked Libs.");
flash->println();
}
return true;
}
// cppcheck-suppress unusedFunction
MX25Series_status_enum_t MX25Series___issue_command(MX25Series_t *dev, MX25Series_COMMAND_enum_t command)
{
ArduinoMX25Series *flash = nullptr;
if(dev->ctx != nullptr) {
flash = static_cast<ArduinoMX25Series *>(dev->ctx);
flash->spi->transfer(command);
return MX25Series_status_ok;
}else
{
return MX25Series_status_error_ctx_nullptr;
}
// Should never get here..
return MX25Series_status_not_reported;
}
// cppcheck-suppress unusedFunction
MX25Series_status_enum_t MX25Series___read(MX25Series_t *dev, size_t length, uint8_t* buffer)
{
memset(buffer, 0, length);
ArduinoMX25Series *flash = nullptr;
if(dev->ctx != nullptr) {
flash = static_cast<ArduinoMX25Series *>(dev->ctx);
flash->spi->transfer(buffer, length);
dev->state = 2;
return MX25Series_status_ok;
}else
{
return MX25Series_status_error_ctx_nullptr;
}
return MX25Series_status_not_reported;
}
// cppcheck-suppress unusedFunction
MX25Series_status_enum_t MX25Series___write(MX25Series_t *dev, size_t length, uint8_t* buffer)
{
ArduinoMX25Series *flash = nullptr;
//Copy data to temporary copy of the data so that buffer does not get overwritten.
uint8_t tmp[length];
memcpy(tmp, buffer, length);
if(dev->ctx != nullptr) {
flash = static_cast<ArduinoMX25Series *>(dev->ctx);
flash->spi->transfer(tmp, length);
dev->state = 3;
return MX25Series_status_ok;
}else
{
return MX25Series_status_error_ctx_nullptr;
}
return MX25Series_status_not_reported;
}
// cppcheck-suppress unusedFunction
void MX25Series___enable_cs_pin(MX25Series_t *dev, bool value)
{
ArduinoMX25Series *flash = nullptr;
if(dev->ctx != nullptr) {
flash = static_cast<ArduinoMX25Series *>(dev->ctx);
}
digitalWrite(dev->cs_pin, !value);
}
// cppcheck-suppress unusedFunction
void MX25Series___enable_reset_pin(MX25Series_t *dev, bool value)
{
ArduinoMX25Series *flash = nullptr;
if(dev->ctx != nullptr) {
flash = static_cast<ArduinoMX25Series *>(dev->ctx);
}
digitalWrite(dev->reset_pin, !value);
}
// cppcheck-suppress unusedFunction
void MX25Series___enable_write_protect_pin(MX25Series_t *dev, bool value)
{
ArduinoMX25Series *flash = nullptr;
if(dev->ctx != nullptr) {
flash = static_cast<ArduinoMX25Series *>(dev->ctx);
// flash->printf("Write Protect: Pin:%i, %s\r\n", dev->cs_pin, value ? "LOW" : "HIGH");
}
digitalWrite(dev->wp_pin, !value);
}