8000 Giga: add pins A8-A11 as pure analog · arduino/ArduinoCore-mbed@3d5a895 · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3d5a895

Browse files
facchinmpennam
authored andcommitted
Giga: add pins A8-A11 as pure analog
1 parent b14f9c6 commit 3d5a895

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

variants/GIGA/pins_arduino.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ static const uint8_t A12 = PIN_A12;
5656
static const uint8_t A13 = PIN_A13;
5757
#define ADC_RESOLUTION 12
5858

59+
#ifdef __cplusplus
60+
#include "pure_analog_pins.h"
61+
#endif
62+
5963
//DACs
6064
#define DAC 1
6165

variants/GIGA/pure_analog_pins.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "pure_analog_pins.h"
2+
#include "AnalogIn.h"
3+
#include "pinDefinitions.h"
4+
5+
PureAnalogPin A8(8);
6+
PureAnalogPin A9(9);
7+
PureAnalogPin A10(10);
8+
PureAnalogPin A11(11);
9+
10+
int getAnalogReadResolution();
11+
12+
int analogRead(PureAnalogPin pin) {
13+
mbed::AnalogIn* adc = g_AAnalogPinDescription[pin.get()].adc;
14+
auto name = g_AAnalogPinDescription[pin.get()].name;
15+
if (adc == NULL) {
16+
adc = new mbed::AnalogIn(name);
17+
g_AAnalogPinDescription[pin.get()].adc = adc;
18+
}
19+
return (adc->read_u16() >> (16 - getAnalogReadResolution()));
20+
}

variants/GIGA/pure_analog_pins.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#ifndef _PURE_ANALOG_PINS_
2+
#define _PURE_ANALOG_PINS_
3+
4+
/******************************************************************************
5+
* INCLUDE
6+
******************************************************************************/
7+
8+
#include "Arduino.h"
9+
10+
/******************************************************************************
11+
* PREPROCESSOR-MAGIC
12+
******************************************************************************/
13+
14+
#define PURE_ANALOG_AS_DIGITAL_ATTRIBUTE __attribute__ ((error("Can't use pins A8-A11 as digital")))
15+
16+
/******************************************************************************
17+
* TYPEDEF
18+
******************************************************************************/
19+
20+
class PureAnalogPin {
21+
public:
22+
PureAnalogPin(int _pin) : pin(_pin) {};
23+
int get() {
24+
return pin;
25+
};
26+
bool operator== (PureAnalogPin const & other) const {
27+
return pin == other.pin;
28+
}
29+
//operator int() = delete;
30+
__attribute__ ((error("Change me to a #define"))) operator int();
31+
private:
32+
int pin;
33+
};
34+
35+
extern PureAnalogPin A8;
36+
extern PureAnalogPin A9;
37+
extern PureAnalogPin A10;
38+
extern PureAnalogPin A11;
39+
40+
/******************************************************************************
41+
* FUNCTION DECLARATION
42+
******************************************************************************/
43+
44+
void PURE_ANALOG_AS_DIGITAL_ATTRIBUTE pinMode (PureAnalogPin pin, PinMode mode);
45+
PinStatus PURE_ANALOG_AS_DIGITAL_ATTRIBUTE digitalRead (PureAnalogPin pin);
46+
void PURE_ANALOG_AS_DIGITAL_ATTRIBUTE digitalWrite(PureAnalogPin pin, PinStatus value);
47+
int analogRead (PureAnalogPin pin);
48+
void PURE_ANALOG_AS_DIGITAL_ATTRIBUTE analogWrite (PureAnalogPin pin, int value);
49+
50+
#undef PURE_ANALOG_AS_DIGITAL_ATTRIBUTE
51+
52+
#endif /* _PURE_ANALOG_PINS_ */

0 commit comments

Comments
 (0)
0