From 8bc3fc20feca9ebe9e9972aeb6b68a81d792c5df Mon Sep 17 00:00:00 2001
From: Paul Sokolovsky <pfalcon@users.sourceforge.net>
Date: Sun, 6 Nov 2016 01:30:19 +0300
Subject: [PATCH] esp8266: Rename "machine" module implementation to use
 contemporary naming.

Previously they used historical "pyb" affix causing confusion and
inconsistency (there's no "pyb" module in modern ports; but people
took esp8266 port as an example, and "pyb" naming kept proliferating,
while other people complained that source structure is not clear).
---
 esp8266/Makefile                           | 18 ++++++------
 esp8266/esp8266.ld                         | 16 +++++-----
 esp8266/esp_mphal.h                        |  2 +-
 esp8266/esponewire.c                       |  2 +-
 esp8266/fatfs_port.c                       |  2 +-
 esp8266/intr.c                             |  2 +-
 esp8266/{modpybadc.c => machine_adc.c}     |  0
 esp8266/{modpybhspi.c => machine_hspi.c}   |  0
 esp8266/{modpybpin.c => machine_pin.c}     |  2 +-
 esp8266/{modpybpwm.c => machine_pwm.c}     |  2 +-
 esp8266/{modpybrtc.c => machine_rtc.c}     |  2 +-
 esp8266/{modpybspi.c => machine_spi.c}     |  0
 esp8266/{modpybuart.c => machine_uart.c}   |  2 +-
 esp8266/{modmachinewdt.c => machine_wdt.c} |  0
 esp8266/modesp.c                           |  3 +-
 esp8266/modmachine.c                       |  3 +-
 esp8266/{modpyb.h => modmachine.h}         |  7 +++++
 esp8266/modonewire.c                       |  2 +-
 esp8266/modpyb.c                           |  4 +--
 esp8266/modpybrtc.h                        | 34 ----------------------
 esp8266/modutime.c                         |  3 +-
 21 files changed, 38 insertions(+), 68 deletions(-)
 rename esp8266/{modpybadc.c => machine_adc.c} (100%)
 rename esp8266/{modpybhspi.c => machine_hspi.c} (100%)
 rename esp8266/{modpybpin.c => machine_pin.c} (99%)
 rename esp8266/{modpybpwm.c => machine_pwm.c} (99%)
 rename esp8266/{modpybrtc.c => machine_rtc.c} (99%)
 rename esp8266/{modpybspi.c => machine_spi.c} (100%)
 rename esp8266/{modpybuart.c => machine_uart.c} (99%)
 rename esp8266/{modmachinewdt.c => machine_wdt.c} (100%)
 rename esp8266/{modpyb.h => modmachine.h} (82%)
 delete mode 100644 esp8266/modpybrtc.h

diff --git a/esp8266/Makefile b/esp8266/Makefile
index 245f95b40..3fce1788c 100644
--- a/esp8266/Makefile
+++ b/esp8266/Makefile
@@ -78,19 +78,19 @@ SRC_C = \
 	espapa102.c \
 	intr.c \
 	modpyb.c \
-	modpybpin.c \
-	modpybpwm.c \
-	modpybrtc.c \
-	modpybadc.c \
-	modpybuart.c \
-	modmachinewdt.c \
-	modpybspi.c \
-	modpybhspi.c \
+	modmachine.c \
+	machine_pin.c \
+	machine_pwm.c \
+	machine_rtc.c \
+	machine_adc.c \
+	machine_uart.c \
+	machine_wdt.c \
+	machine_spi.c \
+	machine_hspi.c \
 	modesp.c \
 	modnetwork.c \
 	modutime.c \
 	moduos.c \
-	modmachine.c \
 	modonewire.c \
 	ets_alt_task.c \
 	fatfs_port.c \
diff --git a/esp8266/esp8266.ld b/esp8266/esp8266.ld
index 5fb6f1379..20b259dff 100644
--- a/esp8266/esp8266.ld
+++ b/esp8266/esp8266.ld
@@ -137,16 +137,16 @@ SECTIONS
         *lexerstr32.o(.literal* .text*)
         *utils.o(.literal* .text*)
         *modpyb.o(.literal*, .text*)
-        *modpybpin.o(.literal*, .text*)
-        *modpybpwm.o(.literal*, .text*)
-        *modpybrtc.o(.literal*, .text*)
-        *modpybadc.o(.literal*, .text*)
-        *modpybuart.o(.literal*, .text*)
+        *machine_pin.o(.literal*, .text*)
+        *machine_pwm.o(.literal*, .text*)
+        *machine_rtc.o(.literal*, .text*)
+        *machine_adc.o(.literal*, .text*)
+        *machine_uart.o(.literal*, .text*)
         *modpybi2c.o(.literal*, .text*)
         *modmachine.o(.literal*, .text*)
-        *modmachinewdt.o(.literal*, .text*)
-        *modpybspi.o(.literal*, .text*)
-        *modpybhspi.o(.literal*, .text*)
+        *machine_wdt.o(.literal*, .text*)
+        *machine_spi.o(.literal*, .text*)
+        *machine_hspi.o(.literal*, .text*)
         *hspi.o(.literal*, .text*)
         *modesp.o(.literal* .text*)
         *modnetwork.o(.literal* .text*)
diff --git a/esp8266/esp_mphal.h b/esp8266/esp_mphal.h
index 7a71c0f03..1622667f9 100644
--- a/esp8266/esp_mphal.h
+++ b/esp8266/esp_mphal.h
@@ -75,7 +75,7 @@ void ets_event_poll(void);
 // C-level pin HAL
 #include "etshal.h"
 #include "gpio.h"
-#include "esp8266/modpyb.h"
+#include "esp8266/modmachine.h"
 #define mp_hal_pin_obj_t uint32_t
 #define mp_hal_get_pin_obj(o) mp_obj_get_pin(o)
 void mp_hal_pin_input(mp_hal_pin_obj_t pin);
diff --git a/esp8266/esponewire.c b/esp8266/esponewire.c
index 797ec0bd2..22bb45b15 100644
--- a/esp8266/esponewire.c
+++ b/esp8266/esponewire.c
@@ -28,7 +28,7 @@
 
 #include "etshal.h"
 #include "user_interface.h"
-#include "modpyb.h"
+#include "modmachine.h"
 #include "esponewire.h"
 
 #define TIMING_RESET1 (0)
diff --git a/esp8266/fatfs_port.c b/esp8266/fatfs_port.c
index b87906f78..9c84f04e4 100644
--- a/esp8266/fatfs_port.c
+++ b/esp8266/fatfs_port.c
@@ -27,7 +27,7 @@
 #include "py/obj.h"
 #include "lib/fatfs/ff.h"
 #include "timeutils.h"
-#include "modpybrtc.h"
+#include "modmachine.h"
 
 DWORD get_fattime(void) {
 
diff --git a/esp8266/intr.c b/esp8266/intr.c
index 62da4a721..456d6cb04 100644
--- a/esp8266/intr.c
+++ b/esp8266/intr.c
@@ -27,7 +27,7 @@
 #include "etshal.h"
 #include "ets_alt_task.h"
 
-#include "modpyb.h"
+#include "modmachine.h"
 
 // this is in a separate file so it can go in iRAM
 void pin_intr_handler_iram(void *arg) {
diff --git a/esp8266/modpybadc.c b/esp8266/machine_adc.c
similarity index 100%
rename from esp8266/modpybadc.c
rename to esp8266/machine_adc.c
diff --git a/esp8266/modpybhspi.c b/esp8266/machine_hspi.c
similarity index 100%
rename from esp8266/modpybhspi.c
rename to esp8266/machine_hspi.c
diff --git a/esp8266/modpybpin.c b/esp8266/machine_pin.c
similarity index 99%
rename from esp8266/modpybpin.c
rename to esp8266/machine_pin.c
index 8916da64f..205c58aae 100644
--- a/esp8266/modpybpin.c
+++ b/esp8266/machine_pin.c
@@ -37,7 +37,7 @@
 #include "py/runtime.h"
 #include "py/gc.h"
 #include "py/mphal.h"
-#include "modpyb.h"
+#include "modmachine.h"
 
 #define GET_TRIGGER(phys_port) \
     GPIO_PIN_INT_TYPE_GET(GPIO_REG_READ(GPIO_PIN_ADDR(phys_port)))
diff --git a/esp8266/modpybpwm.c b/esp8266/machine_pwm.c
similarity index 99%
rename from esp8266/modpybpwm.c
rename to esp8266/machine_pwm.c
index 871e4c3dd..5d30f0965 100644
--- a/esp8266/modpybpwm.c
+++ b/esp8266/machine_pwm.c
@@ -31,7 +31,7 @@
 
 #include "py/nlr.h"
 #include "py/runtime.h"
-#include "modpyb.h"
+#include "modmachine.h"
 
 typedef struct _pyb_pwm_obj_t {
     mp_obj_base_t base;
diff --git a/esp8266/modpybrtc.c b/esp8266/machine_rtc.c
similarity index 99%
rename from esp8266/modpybrtc.c
rename to esp8266/machine_rtc.c
index d69fc47a8..54eeea6f6 100644
--- a/esp8266/modpybrtc.c
+++ b/esp8266/machine_rtc.c
@@ -32,7 +32,7 @@
 #include "py/runtime.h"
 #include "timeutils.h"
 #include "user_interface.h"
-#include "modpyb.h"
+#include "modmachine.h"
 
 typedef struct _pyb_rtc_obj_t {
     mp_obj_base_t base;
diff --git a/esp8266/modpybspi.c b/esp8266/machine_spi.c
similarity index 100%
rename from esp8266/modpybspi.c
rename to esp8266/machine_spi.c
diff --git a/esp8266/modpybuart.c b/esp8266/machine_uart.c
similarity index 99%
rename from esp8266/modpybuart.c
rename to esp8266/machine_uart.c
index 25320fa1e..80e10d131 100644
--- a/esp8266/modpybuart.c
+++ b/esp8266/machine_uart.c
@@ -34,7 +34,7 @@
 #include "py/runtime.h"
 #include "py/stream.h"
 #include "py/mperrno.h"
-#include "modpyb.h"
+#include "modmachine.h"
 
 // UartDev is defined and initialized in rom code.
 extern UartDevice UartDev;
diff --git a/esp8266/modmachinewdt.c b/esp8266/machine_wdt.c
similarity index 100%
rename from esp8266/modmachinewdt.c
rename to esp8266/machine_wdt.c
diff --git a/esp8266/modesp.c b/esp8266/modesp.c
index 827907d42..207422b67 100644
--- a/esp8266/modesp.c
+++ b/esp8266/modesp.c
@@ -45,8 +45,7 @@
 #include "mem.h"
 #include "espneopixel.h"
 #include "espapa102.h"
-#include "modpyb.h"
-#include "modpybrtc.h"
+#include "modmachine.h"
 
 #define MODESP_ESPCONN (0)
 
diff --git a/esp8266/modmachine.c b/esp8266/modmachine.c
index 0ab3c122b..29a72f7e4 100644
--- a/esp8266/modmachine.c
+++ b/esp8266/modmachine.c
@@ -33,8 +33,7 @@
 #include "extmod/machine_mem.h"
 #include "extmod/machine_pulse.h"
 #include "extmod/machine_i2c.h"
-#include "modpyb.h"
-#include "modpybrtc.h"
+#include "modmachine.h"
 
 #include "xtirq.h"
 #include "os_type.h"
diff --git a/esp8266/modpyb.h b/esp8266/modmachine.h
similarity index 82%
rename from esp8266/modpyb.h
rename to esp8266/modmachine.h
index c23a119e8..df7953ecb 100644
--- a/esp8266/modpyb.h
+++ b/esp8266/modmachine.h
@@ -33,4 +33,11 @@ pyb_pin_obj_t *mp_obj_get_pin_obj(mp_obj_t pin_in);
 int pin_get(uint pin);
 void pin_set(uint pin, int value);
 
+extern uint32_t pyb_rtc_alarm0_wake;
+extern uint64_t pyb_rtc_alarm0_expiry;
+
+void pyb_rtc_set_us_since_2000(uint64_t nowus);
+uint64_t pyb_rtc_get_us_since_2000();
+void rtc_prepare_deepsleep(uint64_t sleep_us);
+
 #endif // __MICROPY_INCLUDED_ESP8266_MODPYB_H__
diff --git a/esp8266/modonewire.c b/esp8266/modonewire.c
index 0d8958cee..1bf772240 100644
--- a/esp8266/modonewire.c
+++ b/esp8266/modonewire.c
@@ -29,7 +29,7 @@
 
 #include "py/obj.h"
 #include "py/mphal.h"
-#include "modpyb.h"
+#include "modmachine.h"
 #include "esponewire.h"
 
 STATIC mp_obj_t onewire_timings(mp_obj_t timings_in) {
diff --git a/esp8266/modpyb.c b/esp8266/modpyb.c
index ba53e71b3..9fe8039bc 100644
--- a/esp8266/modpyb.c
+++ b/esp8266/modpyb.c
@@ -28,12 +28,12 @@
 
 #include "py/gc.h"
 #include "gccollect.h"
-#include "modpyb.h"
+#include "modmachine.h"
 
 // The pyb module no longer exists since all functionality now appears
 // elsewhere, in more standard places (eg time, machine modules).  The
 // only remaining function is pyb.info() which has been moved to the
-// esp module, pending deletion/renaming/moving elsewher.
+// esp module, pending deletion/renaming/moving elsewhere.
 
 STATIC mp_obj_t pyb_info(mp_uint_t n_args, const mp_obj_t *args) {
     // print info about memory
diff --git a/esp8266/modpybrtc.h b/esp8266/modpybrtc.h
deleted file mode 100644
index 5b9d9fc76..000000000
--- a/esp8266/modpybrtc.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * This file is part of the Micro Python project, http://micropython.org/
- *
- * The MIT License (MIT)
- *
- * Copyright (c) 2015 Josef Gajdusek
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-extern uint32_t pyb_rtc_alarm0_wake;
-extern uint64_t pyb_rtc_alarm0_expiry;
-
-void pyb_rtc_set_us_since_2000(uint64_t nowus);
-
-uint64_t pyb_rtc_get_us_since_2000();
-
-void rtc_prepare_deepsleep(uint64_t sleep_us);
diff --git a/esp8266/modutime.c b/esp8266/modutime.c
index 1bd1c489d..2adb6c563 100644
--- a/esp8266/modutime.c
+++ b/esp8266/modutime.c
@@ -34,8 +34,7 @@
 #include "py/runtime.h"
 #include "py/mphal.h"
 #include "py/smallint.h"
-#include "modpyb.h"
-#include "modpybrtc.h"
+#include "modmachine.h"
 #include "timeutils.h"
 #include "user_interface.h"
 #include "extmod/utime_mphal.h"
-- 
GitLab