summaryrefslogtreecommitdiff
path: root/esp8266
diff options
context:
space:
mode:
Diffstat (limited to 'esp8266')
-rw-r--r--esp8266/common-hal/microcontroller/Pin.c12
-rw-r--r--esp8266/common-hal/microcontroller/Pin.h4
-rw-r--r--esp8266/common-hal/microcontroller/__init__.c4
-rw-r--r--esp8266/common-hal/nativeio/AnalogIn.c6
4 files changed, 19 insertions, 7 deletions
diff --git a/esp8266/common-hal/microcontroller/Pin.c b/esp8266/common-hal/microcontroller/Pin.c
index 23524e2ca..d20a6a997 100644
--- a/esp8266/common-hal/microcontroller/Pin.c
+++ b/esp8266/common-hal/microcontroller/Pin.c
@@ -25,6 +25,7 @@
*/
#include "common-hal/microcontroller/__init__.h"
+#include "common-hal/microcontroller/Pin.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "eagle_soc.h"
@@ -32,11 +33,16 @@
extern volatile bool adc_in_use;
bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t* pin) {
- return (pin == &pin_TOUT && adc_in_use) ||
- ((READ_PERI_REG(pin->peripheral) &
+ if (pin == &pin_TOUT) {
+ return !adc_in_use;
+ }
+ if (pin->gpio_number == NO_GPIO || pin->gpio_number == SPECIAL_CASE) {
+ return false;
+ }
+ return (READ_PERI_REG(pin->peripheral) &
(PERIPHS_IO_MUX_FUNC<<PERIPHS_IO_MUX_FUNC_S)) == 0 &&
(GPIO_REG_READ(GPIO_ENABLE_ADDRESS) & (1 << pin->gpio_number)) == 0 &&
- (READ_PERI_REG(pin->peripheral) & PERIPHS_IO_MUX_PULLUP) == 0 );
+ (READ_PERI_REG(pin->peripheral) & PERIPHS_IO_MUX_PULLUP) == 0;
}
void reset_pins(void) {
diff --git a/esp8266/common-hal/microcontroller/Pin.h b/esp8266/common-hal/microcontroller/Pin.h
index 428ece1c2..a06e9c195 100644
--- a/esp8266/common-hal/microcontroller/Pin.h
+++ b/esp8266/common-hal/microcontroller/Pin.h
@@ -27,6 +27,10 @@
#ifndef __MICROPY_INCLUDED_ESP8266_COMMON_HAL_MICROCONTROLLER_PIN_H__
#define __MICROPY_INCLUDED_ESP8266_COMMON_HAL_MICROCONTROLLER_PIN_H__
+// Magic values for gpio_number.
+#define NO_GPIO 0xff
+#define SPECIAL_CASE 0xfe
+
void reset_pins(void);
#endif // __MICROPY_INCLUDED_ESP8266_COMMON_HAL_MICROCONTROLLER_PIN_H__
diff --git a/esp8266/common-hal/microcontroller/__init__.c b/esp8266/common-hal/microcontroller/__init__.c
index deb7a6182..f14143e7d 100644
--- a/esp8266/common-hal/microcontroller/__init__.c
+++ b/esp8266/common-hal/microcontroller/__init__.c
@@ -24,6 +24,7 @@
* THE SOFTWARE.
*/
+#include "common-hal/microcontroller/Pin.h"
#include "common-hal/microcontroller/types.h"
#include "shared-bindings/microcontroller/Pin.h"
@@ -61,9 +62,6 @@ const mcu_pin_obj_t pin_## p_name = { \
.peripheral = p_peripheral, \
}
-#define NO_GPIO 0xff
-#define SPECIAL_CASE 0xfe
-
// Using microcontroller names from the datasheet.
// https://cdn-shop.adafruit.com/datasheets/ESP8266_Specifications_English.pdf
// PIN(mcu name) // function notes | module name | huzzah name
diff --git a/esp8266/common-hal/nativeio/AnalogIn.c b/esp8266/common-hal/nativeio/AnalogIn.c
index bf46e930d..57ff607a3 100644
--- a/esp8266/common-hal/nativeio/AnalogIn.c
+++ b/esp8266/common-hal/nativeio/AnalogIn.c
@@ -36,7 +36,7 @@
#include "user_interface.h"
-volatile bool adc_in_use = false;
+volatile bool adc_in_use __attribute__((aligned(4))) = false;
void common_hal_nativeio_analogin_construct(nativeio_analogin_obj_t* self,
const mcu_pin_obj_t *pin) {
@@ -54,3 +54,7 @@ uint16_t common_hal_nativeio_analogin_get_value(nativeio_analogin_obj_t *self) {
// ADC is 10 bit so shift by 6 to make it 16-bit.
return system_adc_read() << 6;
}
+
+float common_hal_nativeio_analogin_get_reference_voltage(nativeio_analogin_obj_t *self) {
+ return 1.0f;
+}