IoAbstraction
PlatformDetermination.h
1 /*
2  * Copyright (c) 2018 https://www.thecoderscorner.com (Dave Cherry).
3  * This product is licensed under an Apache license, see the LICENSE file in the top-level directory.
4  */
5 
6 #ifndef TCLIBRARYDEV_PLATFORMDETERMINATION_H
7 #define TCLIBRARYDEV_PLATFORMDETERMINATION_H
8 
9 // You can add your own local definitions header file here, this enables you to adjust build flags in environments
10 // where there is no easy way to do so with compiler options. Just create an include file "io_local_definitions.h"
11 // at the top level of your project source tree.
12 #if defined __has_include
13 # if __has_include ("zio_local_definitions.h")
14 # include "zio_local_definitions.h"
15 # endif
16 #endif // has include "io_local_definitions"
17 
18 // when not on mbed, we need to load Arduino.h to get the right defines for some boards.
19 #if !defined(__MBED__) && !defined(BUILD_FOR_PICO_CMAKE)
20 #include <Arduino.h>
21 #endif
22 
23 // the purpose of this file is to determine the actual main environment, which has got a bit more tricky now
24 // that some Arduino devices are actually mbed based, but not standard enough to use mbed as usual.
25 // As more Arduino mbed devices become available, I imagine this list will grow, and we may revisit if
26 // it's better to work out how to include the mbed namespace and use our mbed layer instead.
27 
28 // If you have a board that's not properly mapped, please raise an issue and we'll see if it's possible to add it.
29 // This file is shared across IoTaskManager and IoAbstraction
30 
31 // list of devices is pulled from https://github.com/arduino/ArduinoCore-mbed/blob/master/full.variables
32 // set TMIOA_FORCE_ARDUINO_MBED to force IoAbstraction to use Arduino-mbed mode.
33 #if defined(ARDUINO_PICO_REVISION)
34 // on the Earl Philhower pico implementation
35 #include <Arduino.h>
36 # define IOA_USE_ARDUINO
37 # define IOA_ANALOGIN_RES 12
38 # define IOA_ANALOGOUT_RES 10
39 typedef uint8_t pinid_t;
40 #elif defined(ARDUINO_NANO_RP2040_CONNECT) || \
41  defined(ARDUINO_ARDUINO_NANO33BLE) || \
42  defined(ARDUINO_RASPBERRY_PI_PICO) || \
43  defined(ARDUINO_PORTENTA_H7_M7) || \
44  defined(ARDUINO_PORTENTA_H7_M4) || \
45  defined(ARDUINO_EDGE_CONTROL) || \
46  defined(ARDUINO_NICLA) || \
47  defined(ARDUINO_NICLA_VISION) || \
48  defined(TMIOA_FORCE_ARDUINO_MBED) || \
49  defined(ARDUINO_ARCH_MBED)
50 // here we're in a hybrid of mbed and Arduino basically. We treat all abstractions as Arduino though.
51 #include <Arduino.h>
52 # define IOA_USE_ARDUINO
53 # define IOA_ARDUINO_MBED
54 # define IOA_ANALOGIN_RES 12
55 # define IOA_ANALOGOUT_RES 8
56 typedef uint32_t pinid_t;
57 #elif defined(__MBED__)
58 // here we are in full mbed mode
59 # define IOA_USE_MBED
60 #include <mbed.h>
61 typedef uint32_t pinid_t;
62 #elif defined(BUILD_FOR_PICO_CMAKE)
63 #include <pico/stdlib.h>
64 typedef uint8_t pinid_t;
65 #define pgm_read_byte_near(x) (*(x))
66 #else
67 // here we are in full arduino mode (AVR, MKR, ESP etc).
68 # define IOA_USE_ARDUINO
69 #include <Arduino.h>
70 typedef uint8_t pinid_t;
71 #define IOA_DEVICE_HAS_PORTS
72 
73 #if defined(ARDUINO_ARCH_SAMD) && !defined(IO_MKR_FORCE_LOWRES_ANALOG)
74 # define IOA_ANALOGIN_RES 12
75 # define IOA_ANALOGOUT_RES 10
76 #elif defined(ESP32)
77 # define IOA_ANALOGIN_RES 12
78 # define IOA_ANALOGOUT_RES 8
79 #elif defined(ESP8266)
80 # define IOA_ANALOGIN_RES 10
81 # define IOA_ANALOGOUT_RES 10
82 #elif defined(ARDUINO_ARCH_RENESAS_UNO) && !defined(IO_MKR_FORCE_LOWRES_ANALOG)
83 #define IOA_ANALOGIN_RES 14
84 #define IOA_ANALOGOUT_RES 12
85 #else
86 # define IOA_ANALOGIN_RES 10
87 # define IOA_ANALOGOUT_RES 8
88 #endif // SAMD ARCH
89 
90 #endif // __MBED__
91 
92 #endif //TCLIBRARYDEV_PLATFORMDETERMINATION_H