-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwiring.h
More file actions
86 lines (72 loc) · 2.38 KB
/
Copy pathwiring.h
File metadata and controls
86 lines (72 loc) · 2.38 KB
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
/*
* Copyright (c) 2023 CONTROLLINO GmbH.
*
* SPDX-License-Identifier: MIT
*/
#ifndef CONTROLLINO_WIRING_H
#define CONTROLLINO_WIRING_H
/**
* \file controlino_pin_driver.h
*
* Arduino pins API for Controllino RP2040 boards
* Based on https://github.com/arduino/ArduinoCore-mbed/tree/master/variants/NANO_RP2040_CONNECT
*
* \author Pedro Marquez @pmmarquez, CONTROLLINO Firmware Team
*/
#include "Arduino.h"
#include "cy8c9520.h"
#include "mcp3564.h"
#include "ad5664.h"
/**
* \brief Controllino Rp2040 pin class
*/
class ControllinoPin{
public:
typedef enum { CY8C9520_PIN, MCP3564_PIN, AD5664_PIN, RP2040_PIN} _pin_type_t;
ControllinoPin(int pin, _pin_type_t type): _pin(pin), _type(type)
{
setMode(INPUT);
_setDigitalThreshold(~0U);
};
bool operator== (ControllinoPin const& other) const { return _pin == other._pin; };
pin_size_t getPin(void) { return _pin; };
_pin_type_t getType(void) { return _type; };
void setMode(PinMode mode) { _mode = mode; };
PinMode getMode(void) { return _mode; };
void _setDigitalThreshold(uint32_t threshold) { _digitalThreshold = threshold; };
uint32_t _getDigitalThreshold(void) { return _digitalThreshold; };
private:
pin_size_t _pin;
_pin_type_t _type;
PinMode _mode;
uint32_t _digitalThreshold;
};
/**
*\brief Get the ControllinoPin* from integer pin definition
*
* \param pin Integer pin definition
* \return ControllinoPin* or nullptr
*/
extern ControllinoPin* getControllinoPin(int pin);
/**
*\brief Similar to Arduino API functions for compatibility with ControllinoPin*
*/
extern void pinMode(ControllinoPin* pin, PinMode mode);
extern PinStatus digitalRead(ControllinoPin* pin);
extern void digitalWrite(ControllinoPin* pin, PinStatus value);
extern int analogRead(ControllinoPin* pin);
extern void analogWrite(ControllinoPin* pin, int value);
/**
*\brief Digital threshold API to implement a digital input with an analog input only pin
*/
extern void setDigitalThreshold(ControllinoPin* pin, uint32_t threshold);
extern uint32_t getDigitalThreshold(ControllinoPin* pin);
extern void setDigitalThreshold(pin_size_t pin, uint32_t threshold); // From integer pin definition
extern uint32_t getDigitalThreshold(pin_size_t pin); // From integer pin definition
/**
* \brief Peripherals interfaces
*/
extern cy8c9520_t* dev_cy8c9520;
extern mcp3564_t* dev_mcp3564;
extern ad5664_t* dev_ad5664;
#endif // CONTROLLINO_WIRING_H