all: Reformat C and Python source code with tools/codeformat.py.

This is run with uncrustify 0.70.1, and black 19.10b0.
diff --git a/ports/esp8266/boards/manifest.py b/ports/esp8266/boards/manifest.py
index b6df53f..de719f8 100644
--- a/ports/esp8266/boards/manifest.py
+++ b/ports/esp8266/boards/manifest.py
@@ -1,5 +1,5 @@
-freeze('$(PORT_DIR)/modules')
-freeze('$(MPY_DIR)/tools', ('upip.py', 'upip_utarfile.py'))
-freeze('$(MPY_DIR)/drivers/dht', 'dht.py')
-freeze('$(MPY_DIR)/drivers/onewire')
-include('$(MPY_DIR)/extmod/webrepl/manifest.py')
+freeze("$(PORT_DIR)/modules")
+freeze("$(MPY_DIR)/tools", ("upip.py", "upip_utarfile.py"))
+freeze("$(MPY_DIR)/drivers/dht", "dht.py")
+freeze("$(MPY_DIR)/drivers/onewire")
+include("$(MPY_DIR)/extmod/webrepl/manifest.py")
diff --git a/ports/esp8266/boards/manifest_release.py b/ports/esp8266/boards/manifest_release.py
index f2788c8..ab86fa3 100644
--- a/ports/esp8266/boards/manifest_release.py
+++ b/ports/esp8266/boards/manifest_release.py
@@ -1,27 +1,27 @@
-include('manifest.py')
+include("manifest.py")
 
 # drivers
-freeze('$(MPY_DIR)/drivers/display', 'ssd1306.py')
+freeze("$(MPY_DIR)/drivers/display", "ssd1306.py")
 
 # file utilities
-freeze('$(MPY_LIB_DIR)/upysh', 'upysh.py')
+freeze("$(MPY_LIB_DIR)/upysh", "upysh.py")
 
 # uasyncio
-freeze('$(MPY_LIB_DIR)/uasyncio', 'uasyncio/__init__.py')
-freeze('$(MPY_LIB_DIR)/uasyncio.core', 'uasyncio/core.py')
+freeze("$(MPY_LIB_DIR)/uasyncio", "uasyncio/__init__.py")
+freeze("$(MPY_LIB_DIR)/uasyncio.core", "uasyncio/core.py")
 
 # requests
-freeze('$(MPY_LIB_DIR)/urequests', 'urequests.py')
-freeze('$(MPY_LIB_DIR)/urllib.urequest', 'urllib/urequest.py')
+freeze("$(MPY_LIB_DIR)/urequests", "urequests.py")
+freeze("$(MPY_LIB_DIR)/urllib.urequest", "urllib/urequest.py")
 
 # umqtt with examples
-freeze('$(MPY_LIB_DIR)/umqtt.simple', 'umqtt/simple.py')
-freeze('$(MPY_LIB_DIR)/umqtt.robust', 'umqtt/robust.py')
-freeze('$(MPY_LIB_DIR)/umqtt.simple', 'example_pub_button.py')
-freeze('$(MPY_LIB_DIR)/umqtt.simple', 'example_sub_led.py')
+freeze("$(MPY_LIB_DIR)/umqtt.simple", "umqtt/simple.py")
+freeze("$(MPY_LIB_DIR)/umqtt.robust", "umqtt/robust.py")
+freeze("$(MPY_LIB_DIR)/umqtt.simple", "example_pub_button.py")
+freeze("$(MPY_LIB_DIR)/umqtt.simple", "example_sub_led.py")
 
 # HTTP examples
-freeze('$(MPY_DIR)/examples/network', 'http_client.py')
-freeze('$(MPY_DIR)/examples/network', 'http_client_ssl.py')
-freeze('$(MPY_DIR)/examples/network', 'http_server.py')
-freeze('$(MPY_DIR)/examples/network', 'http_server_ssl.py')
+freeze("$(MPY_DIR)/examples/network", "http_client.py")
+freeze("$(MPY_DIR)/examples/network", "http_client_ssl.py")
+freeze("$(MPY_DIR)/examples/network", "http_server.py")
+freeze("$(MPY_DIR)/examples/network", "http_server_ssl.py")
diff --git a/ports/esp8266/esp_init_data.c b/ports/esp8266/esp_init_data.c
index b14de57..eb4d99e 100644
--- a/ports/esp8266/esp_init_data.c
+++ b/ports/esp8266/esp_init_data.c
@@ -36,20 +36,20 @@
 extern char flashchip;
 
 static const uint8_t default_init_data[] __attribute__((aligned(4))) = {
-0x05, 0x00, 0x04, 0x02, 0x05, 0x05, 0x05, 0x02, 0x05, 0x00, 0x04, 0x05, 0x05, 0x04, 0x05, 0x05,
-0x04, 0xfe, 0xfd, 0xff, 0xf0, 0xf0, 0xf0, 0xe0, 0xe0, 0xe0, 0xe1, 0x0a, 0xff, 0xff, 0xf8, 0x00,
-0xf8, 0xf8, 0x52, 0x4e, 0x4a, 0x44, 0x40, 0x38, 0x00, 0x00, 0x01, 0x01, 0x02, 0x03, 0x04, 0x05,
-0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0xe1, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x93, 0x43, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+    0x05, 0x00, 0x04, 0x02, 0x05, 0x05, 0x05, 0x02, 0x05, 0x00, 0x04, 0x05, 0x05, 0x04, 0x05, 0x05,
+    0x04, 0xfe, 0xfd, 0xff, 0xf0, 0xf0, 0xf0, 0xe0, 0xe0, 0xe0, 0xe1, 0x0a, 0xff, 0xff, 0xf8, 0x00,
+    0xf8, 0xf8, 0x52, 0x4e, 0x4a, 0x44, 0x40, 0x38, 0x00, 0x00, 0x01, 0x01, 0x02, 0x03, 0x04, 0x05,
+    0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0xe1, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x93, 0x43, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
 };
 
 void firmware_start(void) {
     // For SDK 1.5.2, either address has shifted and not mirrored in
     // eagle.rom.addr.v6.ld, or extra initial member was added.
-    SpiFlashChip *flash = (SpiFlashChip*)(&flashchip + 4);
+    SpiFlashChip *flash = (SpiFlashChip *)(&flashchip + 4);
 
     char buf[128];
     SPIRead(flash->chip_size - 4 * 0x1000, buf, sizeof(buf));
@@ -73,5 +73,5 @@
         SPIWrite(flash->chip_size - 4 * 0x1000, buf, sizeof(buf));
     }
 
-    asm("j call_user_start");
+    asm ("j call_user_start");
 }
diff --git a/ports/esp8266/esp_mphal.c b/ports/esp8266/esp_mphal.c
index d840cf0..d711345 100644
--- a/ports/esp8266/esp_mphal.c
+++ b/ports/esp8266/esp_mphal.c
@@ -74,7 +74,7 @@
         #if 0
         // Idles CPU but need more testing before enabling
         if (!ets_loop_iter()) {
-            asm("waiti 0");
+            asm ("waiti 0");
         }
         #else
         mp_hal_delay_us(1);
@@ -189,7 +189,7 @@
 void *ets_get_esf_buf_ctlblk(void) {
     // Get literal ptr before start of esf_rx_buf_alloc func
     extern void *esf_rx_buf_alloc();
-    return ((void**)esf_rx_buf_alloc)[-1];
+    return ((void **)esf_rx_buf_alloc)[-1];
 }
 
 // Get number of esf_buf free buffers of given type, as encoded by index
@@ -198,10 +198,10 @@
 // 1 - tx buffer, 5 - management frame tx buffer; 8 - rx buffer
 int ets_esf_free_bufs(int idx) {
     uint32_t *p = ets_get_esf_buf_ctlblk();
-    uint32_t *b = (uint32_t*)p[idx];
+    uint32_t *b = (uint32_t *)p[idx];
     int cnt = 0;
     while (b) {
-        b = (uint32_t*)b[0x20 / 4];
+        b = (uint32_t *)b[0x20 / 4];
         cnt++;
     }
     return cnt;
diff --git a/ports/esp8266/esp_mphal.h b/ports/esp8266/esp_mphal.h
index 8712a2a..eaae18f 100644
--- a/ports/esp8266/esp_mphal.h
+++ b/ports/esp8266/esp_mphal.h
@@ -48,9 +48,9 @@
 
 uint32_t mp_hal_ticks_us(void);
 __attribute__((always_inline)) static inline uint32_t mp_hal_ticks_cpu(void) {
-  uint32_t ccount;
-  __asm__ __volatile__("rsr %0,ccount":"=a" (ccount));
-  return ccount;
+    uint32_t ccount;
+    __asm__ __volatile__ ("rsr %0,ccount" : "=a" (ccount));
+    return ccount;
 }
 
 void mp_hal_delay_us(uint32_t);
@@ -86,16 +86,16 @@
 #define mp_hal_pin_od_low(p) do { \
         if ((p) == 16) { WRITE_PERI_REG(RTC_GPIO_ENABLE, (READ_PERI_REG(RTC_GPIO_ENABLE) & ~1) | 1); } \
         else { gpio_output_set(0, 1 << (p), 1 << (p), 0); } \
-    } while (0)
+} while (0)
 #define mp_hal_pin_od_high(p) do { \
         if ((p) == 16) { WRITE_PERI_REG(RTC_GPIO_ENABLE, (READ_PERI_REG(RTC_GPIO_ENABLE) & ~1)); } \
         else { gpio_output_set(0, 0, 0, 1 << (p)); /* set as input to avoid glitches */ } \
-    } while (0)
+} while (0)
 // The DHT driver requires using the open-drain feature of the GPIO to get it to work reliably
 #define mp_hal_pin_od_high_dht(p) do { \
         if ((p) == 16) { WRITE_PERI_REG(RTC_GPIO_ENABLE, (READ_PERI_REG(RTC_GPIO_ENABLE) & ~1)); } \
         else { gpio_output_set(1 << (p), 0, 1 << (p), 0); } \
-    } while (0)
+} while (0)
 #define mp_hal_pin_read(p) pin_get(p)
 #define mp_hal_pin_write(p, v) pin_set((p), (v))
 
diff --git a/ports/esp8266/espapa102.c b/ports/esp8266/espapa102.c
index 4295fe4..2bea266 100644
--- a/ports/esp8266/espapa102.c
+++ b/ports/esp8266/espapa102.c
@@ -33,7 +33,7 @@
 #include "user_interface.h"
 #include "espapa102.h"
 
-#define NOP asm volatile(" nop \n\t")
+#define NOP asm volatile (" nop \n\t")
 
 static inline void _esp_apa102_send_byte(uint32_t clockPinMask, uint32_t dataPinMask, uint8_t byte) {
     for (uint32_t i = 0; i < 8; i++) {
diff --git a/ports/esp8266/espneopixel.c b/ports/esp8266/espneopixel.c
index 6c76591..d2166a8 100644
--- a/ports/esp8266/espneopixel.c
+++ b/ports/esp8266/espneopixel.c
@@ -18,48 +18,58 @@
 
 void /*ICACHE_RAM_ATTR*/ esp_neopixel_write(uint8_t pin, uint8_t *pixels, uint32_t numBytes, bool is800KHz) {
 
-  uint8_t *p, *end, pix, mask;
-  uint32_t t, time0, time1, period, c, startTime, pinMask;
+    uint8_t *p, *end, pix, mask;
+    uint32_t t, time0, time1, period, c, startTime, pinMask;
 
-  pinMask   = 1 << pin;
-  p         =  pixels;
-  end       =  p + numBytes;
-  pix       = *p++;
-  mask      = 0x80;
-  startTime = 0;
+    pinMask = 1 << pin;
+    p = pixels;
+    end = p + numBytes;
+    pix = *p++;
+    mask = 0x80;
+    startTime = 0;
 
-  uint32_t fcpu = system_get_cpu_freq() * 1000000;
+    uint32_t fcpu = system_get_cpu_freq() * 1000000;
 
-#ifdef NEO_KHZ400
-  if(is800KHz) {
-#endif
-    time0  = fcpu / 2857143; // 0.35us
-    time1  = fcpu / 1250000; // 0.8us
-    period = fcpu /  800000; // 1.25us per bit
-#ifdef NEO_KHZ400
-  } else { // 400 KHz bitstream
-    time0  = fcpu / 2000000; // 0.5uS
-    time1  = fcpu /  833333; // 1.2us
-    period = fcpu /  400000; // 2.5us per bit
-  }
-#endif
+    #ifdef NEO_KHZ400
+    if (is800KHz) {
+    #endif
+    time0 = fcpu / 2857143;  // 0.35us
+    time1 = fcpu / 1250000;  // 0.8us
+    period = fcpu / 800000;  // 1.25us per bit
+    #ifdef NEO_KHZ400
+} else {   // 400 KHz bitstream
+    time0 = fcpu / 2000000;  // 0.5uS
+    time1 = fcpu / 833333;   // 1.2us
+    period = fcpu / 400000;  // 2.5us per bit
+}
+    #endif
 
-  uint32_t irq_state = mp_hal_quiet_timing_enter();
-  for(t = time0;; t = time0) {
-    if(pix & mask) t = time1;                             // Bit high duration
-    while(((c = mp_hal_ticks_cpu()) - startTime) < period); // Wait for bit start
-    GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinMask);       // Set high
-    startTime = c;                                        // Save start time
-    while(((c = mp_hal_ticks_cpu()) - startTime) < t);      // Wait high duration
-    GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinMask);       // Set low
-    if(!(mask >>= 1)) {                                   // Next bit/byte
-      if(p >= end) break;
-      pix  = *p++;
-      mask = 0x80;
+    uint32_t irq_state = mp_hal_quiet_timing_enter();
+    for (t = time0;; t = time0) {
+        if (pix & mask) {
+            t = time1;                                    // Bit high duration
+        }
+        while (((c = mp_hal_ticks_cpu()) - startTime) < period) {
+            ;                                               // Wait for bit start
+        }
+        GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinMask);   // Set high
+        startTime = c;                                    // Save start time
+        while (((c = mp_hal_ticks_cpu()) - startTime) < t) {
+            ;                                               // Wait high duration
+        }
+        GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinMask);   // Set low
+        if (!(mask >>= 1)) {                              // Next bit/byte
+            if (p >= end) {
+                break;
+            }
+            pix = *p++;
+            mask = 0x80;
+        }
     }
-  }
-  while((mp_hal_ticks_cpu() - startTime) < period); // Wait for last bit
-  mp_hal_quiet_timing_exit(irq_state);
+    while ((mp_hal_ticks_cpu() - startTime) < period) {
+        ;                                           // Wait for last bit
+    }
+    mp_hal_quiet_timing_exit(irq_state);
 }
 
 #endif // MICROPY_ESP8266_NEOPIXEL
diff --git a/ports/esp8266/esppwm.c b/ports/esp8266/esppwm.c
index 33eaf3b..3759bb5 100644
--- a/ports/esp8266/esppwm.c
+++ b/ports/esp8266/esppwm.c
@@ -61,10 +61,10 @@
 //XXX: 0xffffffff/(80000000/16)=35A
 #define US_TO_RTC_TIMER_TICKS(t)          \
     ((t) ?                                   \
-     (((t) > 0x35A) ?                   \
-      (((t)>>2) * ((APB_CLK_FREQ>>4)/250000) + ((t)&0x3) * ((APB_CLK_FREQ>>4)/1000000))  :    \
-      (((t) *(APB_CLK_FREQ>>4)) / 1000000)) :    \
-     0)
+    (((t) > 0x35A) ?                   \
+    (((t) >> 2) * ((APB_CLK_FREQ >> 4) / 250000) + ((t) & 0x3) * ((APB_CLK_FREQ >> 4) / 1000000))  :    \
+    (((t) * (APB_CLK_FREQ >> 4)) / 1000000)) :    \
+    0)
 
 //FRC1
 #define FRC1_ENABLE_TIMER  BIT7
@@ -81,8 +81,7 @@
 } TIMER_INT_MODE;
 
 STATIC void ICACHE_FLASH_ATTR
-pwm_insert_sort(struct pwm_single_param pwm[], uint8 n)
-{
+pwm_insert_sort(struct pwm_single_param pwm[], uint8 n) {
     uint8 i;
 
     for (i = 1; i < n; i++) {
@@ -109,17 +108,16 @@
 STATIC volatile uint8 critical = 0;
 
 #define LOCK_PWM(c)  do {                       \
-    while( (c)==1 );                            \
-    (c) = 1;                                    \
+        while ( (c) == 1);                            \
+        (c) = 1;                                    \
 } while (0)
 
 #define UNLOCK_PWM(c) do {                      \
-    (c) = 0;                                    \
+        (c) = 0;                                    \
 } while (0)
 
 void ICACHE_FLASH_ATTR
-pwm_start(void)
-{
+pwm_start(void) {
     uint8 i, j;
     PWM_DBG("--Function pwm_start() is called\n");
     PWM_DBG("pwm_gpio:%x,pwm_channel_num:%d\n",pwm_gpio,pwm_channel_num);
@@ -169,7 +167,7 @@
     }
 
     // step 5: last channel needs to clean
-    local_single[*local_channel-1].gpio_clear = 0;
+    local_single[*local_channel - 1].gpio_clear = 0;
 
     // step 6: if first channel duty is 0, remove it
     if (local_single[0].h_time == 0) {
@@ -212,17 +210,17 @@
  * Returns      : NONE
 *******************************************************************************/
 void ICACHE_FLASH_ATTR
-pwm_set_duty(int16_t duty, uint8 channel)
-{
+pwm_set_duty(int16_t duty, uint8 channel) {
     uint8 i;
-    for(i=0;i<pwm_channel_num;i++){
-        if(pwm_out_io_num[i] == channel){
+    for (i = 0; i < pwm_channel_num; i++) {
+        if (pwm_out_io_num[i] == channel) {
             channel = i;
             break;
         }
     }
-    if(i==pwm_channel_num)      // non found
+    if (i == pwm_channel_num) {    // non found
         return;
+    }
 
     LOCK_PWM(critical);   // enter critical
     if (duty < 1) {
@@ -242,8 +240,7 @@
  * Returns      : NONE
 *******************************************************************************/
 void ICACHE_FLASH_ATTR
-pwm_set_freq(uint16 freq, uint8 channel)
-{
+pwm_set_freq(uint16 freq, uint8 channel) {
     LOCK_PWM(critical);   // enter critical
     if (freq > PWM_FREQ_MAX) {
         pwm.freq = PWM_FREQ_MAX;
@@ -264,17 +261,17 @@
  * Returns      : NONE
 *******************************************************************************/
 uint16 ICACHE_FLASH_ATTR
-pwm_get_duty(uint8 channel)
-{
+pwm_get_duty(uint8 channel) {
     uint8 i;
-    for(i=0;i<pwm_channel_num;i++){
-        if(pwm_out_io_num[i] == channel){
+    for (i = 0; i < pwm_channel_num; i++) {
+        if (pwm_out_io_num[i] == channel) {
             channel = i;
             break;
         }
     }
-    if(i==pwm_channel_num)      // non found
+    if (i == pwm_channel_num) {    // non found
         return 0;
+    }
 
     return pwm.duty[channel];
 }
@@ -286,8 +283,7 @@
  * Returns      : uint16 : pwm frequency
 *******************************************************************************/
 uint16 ICACHE_FLASH_ATTR
-pwm_get_freq(uint8 channel)
-{
+pwm_get_freq(uint8 channel) {
     return pwm.freq;
 }
 
@@ -299,8 +295,7 @@
  * Returns      : NONE
 *******************************************************************************/
 STATIC void ICACHE_RAM_ATTR
-pwm_tim1_intr_handler(void *dummy)
-{
+pwm_tim1_intr_handler(void *dummy) {
     (void)dummy;
     uint8 local_toggle = pwm_toggle;                        // pwm_toggle may change outside
     RTC_CLR_REG_MASK(FRC1_INT_ADDRESS, FRC1_INT_CLR_MASK);
@@ -310,17 +305,17 @@
         pwm_channel = &pwm_channel_toggle[local_toggle];
 
         gpio_output_set(pwm_single[*pwm_channel - 1].gpio_set,
-                        pwm_single[*pwm_channel - 1].gpio_clear,
-                        pwm_gpio,
-                        0);
+            pwm_single[*pwm_channel - 1].gpio_clear,
+            pwm_gpio,
+            0);
 
         pwm_current_channel = 0;
 
         RTC_REG_WRITE(FRC1_LOAD_ADDRESS, pwm_single[pwm_current_channel].h_time);
     } else {
         gpio_output_set(pwm_single[pwm_current_channel].gpio_set,
-                        pwm_single[pwm_current_channel].gpio_clear,
-                        pwm_gpio, 0);
+            pwm_single[pwm_current_channel].gpio_clear,
+            pwm_gpio, 0);
 
         pwm_current_channel++;
         RTC_REG_WRITE(FRC1_LOAD_ADDRESS, pwm_single[pwm_current_channel].h_time);
@@ -335,14 +330,13 @@
  * Returns      : NONE
 *******************************************************************************/
 void ICACHE_FLASH_ATTR
-pwm_init(void)
-{
+pwm_init(void) {
     uint8 i;
 
     RTC_REG_WRITE(FRC1_CTRL_ADDRESS,  //FRC2_AUTO_RELOAD|
-                  DIVDED_BY_16
-                  | FRC1_ENABLE_TIMER
-                  | TM_EDGE_INT);
+        DIVDED_BY_16
+        | FRC1_ENABLE_TIMER
+        | TM_EDGE_INT);
     RTC_REG_WRITE(FRC1_LOAD_ADDRESS, 0);
 
     for (i = 0; i < PWM_CHANNEL; i++) {
@@ -359,7 +353,7 @@
 }
 
 int ICACHE_FLASH_ATTR
-pwm_add(uint8_t pin_id, uint32_t pin_mux, uint32_t pin_func){
+pwm_add(uint8_t pin_id, uint32_t pin_mux, uint32_t pin_func) {
     PWM_DBG("--Function pwm_add() is called. channel:%d\n", channel);
     PWM_DBG("pwm_gpio:%x,pwm_channel_num:%d\n",pwm_gpio,pwm_channel_num);
     PWM_DBG("pwm_out_io_num[0]:%d,[1]:%d,[2]:%d\n",pwm_out_io_num[0],pwm_out_io_num[1],pwm_out_io_num[2]);
@@ -375,16 +369,17 @@
         return -1;
     }
     uint8 i;
-    for(i=0;i<PWM_CHANNEL;i++){
-        if(pwm_out_io_num[i]==channel)  // already exist
+    for (i = 0; i < PWM_CHANNEL; i++) {
+        if (pwm_out_io_num[i] == channel) { // already exist
             return channel;
-        if(pwm_out_io_num[i] == -1){ // empty exist
+        }
+        if (pwm_out_io_num[i] == -1) { // empty exist
             LOCK_PWM(critical);   // enter critical
             pwm_out_io_num[i] = channel;
             pwm.duty[i] = 0;
             pwm_gpio |= (1 << pin_num[channel]);
             PIN_FUNC_SELECT(pin_mux, pin_func);
-            GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(pin_num[channel])), GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(pin_num[channel]))) & (~ GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE))); //disable open drain;
+            GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(pin_num[channel])), GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(pin_num[channel]))) & (~GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)));  //disable open drain;
             pwm_channel_num++;
             UNLOCK_PWM(critical);   // leave critical
             return channel;
@@ -394,23 +389,23 @@
 }
 
 bool ICACHE_FLASH_ATTR
-pwm_delete(uint8 channel){
+pwm_delete(uint8 channel) {
     PWM_DBG("--Function pwm_delete() is called. channel:%d\n", channel);
     PWM_DBG("pwm_gpio:%x,pwm_channel_num:%d\n",pwm_gpio,pwm_channel_num);
     PWM_DBG("pwm_out_io_num[0]:%d,[1]:%d,[2]:%d\n",pwm_out_io_num[0],pwm_out_io_num[1],pwm_out_io_num[2]);
     PWM_DBG("pwm.duty[0]:%d,[1]:%d,[2]:%d\n",pwm.duty[0],pwm.duty[1],pwm.duty[2]);
     uint8 i,j;
-    for(i=0;i<pwm_channel_num;i++){
-        if(pwm_out_io_num[i]==channel){  // exist
+    for (i = 0; i < pwm_channel_num; i++) {
+        if (pwm_out_io_num[i] == channel) { // exist
             LOCK_PWM(critical);   // enter critical
             pwm_out_io_num[i] = -1;
             pwm_gpio &= ~(1 << pin_num[channel]);   //clear the bit
-            for(j=i;j<pwm_channel_num-1;j++){
-                pwm_out_io_num[j] = pwm_out_io_num[j+1];
-                pwm.duty[j] = pwm.duty[j+1];
+            for (j = i; j < pwm_channel_num - 1; j++) {
+                pwm_out_io_num[j] = pwm_out_io_num[j + 1];
+                pwm.duty[j] = pwm.duty[j + 1];
             }
-            pwm_out_io_num[pwm_channel_num-1] = -1;
-            pwm.duty[pwm_channel_num-1] = 0;
+            pwm_out_io_num[pwm_channel_num - 1] = -1;
+            pwm.duty[pwm_channel_num - 1] = 0;
             pwm_channel_num--;
             UNLOCK_PWM(critical);   // leave critical
             return true;
diff --git a/ports/esp8266/ets_alt_task.c b/ports/esp8266/ets_alt_task.c
index 0b1615d..ce27758 100644
--- a/ports/esp8266/ets_alt_task.c
+++ b/ports/esp8266/ets_alt_task.c
@@ -25,9 +25,9 @@
 static void *idle_arg;
 
 #if ESP_SDK_VERSION >= 010500
-# define FIRST_PRIO 0
+#define FIRST_PRIO 0
 #else
-# define FIRST_PRIO 0x14
+#define FIRST_PRIO 0x14
 #endif
 #define LAST_PRIO 0x20
 #define PRIO2ID(prio) ((prio) - FIRST_PRIO)
@@ -38,7 +38,9 @@
     int id = PRIO2ID(prio);
     if (id < 0 || id >= MP_ARRAY_SIZE(emu_tasks)) {
         printf("task prio out of range: %d\n", prio);
-        while (1);
+        while (1) {
+            ;
+        }
     }
     return id;
 }
@@ -62,9 +64,9 @@
 bool ets_task(os_task_t task, uint8 prio, os_event_t *queue, uint8 qlen) {
     static unsigned cnt;
     printf("#%d ets_task(%p, %d, %p, %d)\n", cnt++, task, prio, queue, qlen);
-#if USE_ETS_TASK
+    #if USE_ETS_TASK
     return _ets_task(task, prio, queue, qlen);
-#else
+    #else
     int id = prio2id(prio);
     emu_tasks[id].task = task;
     emu_tasks[id].queue = queue;
@@ -72,14 +74,14 @@
     emu_tasks[id].i_get = 0;
     emu_tasks[id].i_put = 0;
     return true;
-#endif
+    #endif
 }
 
 bool ets_post(uint8 prio, os_signal_t sig, os_param_t param) {
 //    static unsigned cnt; printf("#%d ets_post(%d, %x, %x)\n", cnt++, prio, sig, param);
-#if USE_ETS_TASK
+    #if USE_ETS_TASK
     return _ets_post(prio, sig, param);
-#else
+    #else
     ets_intr_lock();
 
     const int id = prio2id(prio);
@@ -105,7 +107,7 @@
     ets_intr_unlock();
 
     return 0;
-#endif
+    #endif
 }
 
 int ets_loop_iter_disable = 0;
@@ -193,7 +195,7 @@
     ets_isr_attach(10, my_timer_isr, NULL);
     SET_PERI_REG_MASK(0x3FF00004, 4);
     ETS_INTR_ENABLE(10);
-    ets_task((os_task_t)0x40002E3C, 0x1f, (os_event_t*)0x3FFFDDC0, 4);
+    ets_task((os_task_t)0x40002E3C, 0x1f, (os_event_t *)0x3FFFDDC0, 4);
 
     WRITE_PERI_REG(PERIPHS_TIMER_BASEDDR + 0x30, 0);
     WRITE_PERI_REG(PERIPHS_TIMER_BASEDDR + 0x28, 0x88);
@@ -203,19 +205,19 @@
 #endif
 
 bool ets_run(void) {
-#if USE_ETS_TASK
+    #if USE_ETS_TASK
     #if SDK_BELOW_1_1_1
     ets_isr_attach(10, my_timer_isr, NULL);
     #endif
     _ets_run();
-#else
+    #else
 //    ets_timer_init();
-    *(char*)0x3FFFC6FC = 0;
+    *(char *)0x3FFFC6FC = 0;
     ets_intr_lock();
     printf("ets_alt_task: ets_run\n");
-#if DEBUG
+    #if DEBUG
     dump_tasks();
-#endif
+    #endif
     ets_intr_unlock();
     while (1) {
         if (!ets_loop_iter()) {
@@ -224,11 +226,11 @@
             if (idle_cb) {
                 idle_cb(idle_arg);
             }
-            asm("waiti 0");
+            asm ("waiti 0");
             ets_intr_unlock();
         }
     }
-#endif
+    #endif
 }
 
 void ets_set_idle_cb(void (*handler)(void *), void *arg) {
diff --git a/ports/esp8266/etshal.h b/ports/esp8266/etshal.h
index 8d64573..f7b34b8 100644
--- a/ports/esp8266/etshal.h
+++ b/ports/esp8266/etshal.h
@@ -4,7 +4,7 @@
 #include <os_type.h>
 
 // see http://esp8266-re.foogod.com/wiki/Random_Number_Generator
-#define WDEV_HWRNG ((volatile uint32_t*)0x3ff20e44)
+#define WDEV_HWRNG ((volatile uint32_t *)0x3ff20e44)
 
 void ets_delay_us(uint16_t us);
 void ets_intr_lock(void);
diff --git a/ports/esp8266/fatfs_port.c b/ports/esp8266/fatfs_port.c
index a8865c8..8cef0ac 100644
--- a/ports/esp8266/fatfs_port.c
+++ b/ports/esp8266/fatfs_port.c
@@ -38,6 +38,6 @@
     timeutils_struct_time_t tm;
     timeutils_seconds_since_2000_to_struct_time(secs, &tm);
 
-    return (((DWORD)(tm.tm_year - 1980) << 25) | ((DWORD)tm.tm_mon << 21) | ((DWORD)tm.tm_mday << 16) |
-           ((DWORD)tm.tm_hour << 11) | ((DWORD)tm.tm_min << 5) | ((DWORD)tm.tm_sec >> 1));
+    return ((DWORD)(tm.tm_year - 1980) << 25) | ((DWORD)tm.tm_mon << 21) | ((DWORD)tm.tm_mday << 16) |
+           ((DWORD)tm.tm_hour << 11) | ((DWORD)tm.tm_min << 5) | ((DWORD)tm.tm_sec >> 1);
 }
diff --git a/ports/esp8266/gccollect.c b/ports/esp8266/gccollect.c
index dbe7bc1..3618a56 100644
--- a/ports/esp8266/gccollect.c
+++ b/ports/esp8266/gccollect.c
@@ -44,7 +44,7 @@
     mp_uint_t sp = gc_helper_get_regs_and_sp(regs);
 
     // trace the stack, including the registers (since they live on the stack in this function)
-    gc_collect_root((void**)sp, (STACK_END - sp) / sizeof(uint32_t));
+    gc_collect_root((void **)sp, (STACK_END - sp) / sizeof(uint32_t));
 
     // end the GC
     gc_collect_end();
diff --git a/ports/esp8266/help.c b/ports/esp8266/help.c
index 0a851f4..4dd586c 100644
--- a/ports/esp8266/help.c
+++ b/ports/esp8266/help.c
@@ -27,28 +27,28 @@
 #include "py/builtin.h"
 
 const char esp_help_text[] =
-"Welcome to MicroPython!\n"
-"\n"
-"For online docs please visit http://docs.micropython.org/en/latest/esp8266/ .\n"
-"For diagnostic information to include in bug reports execute 'import port_diag'.\n"
-"\n"
-"Basic WiFi configuration:\n"
-"\n"
-"import network\n"
-"sta_if = network.WLAN(network.STA_IF); sta_if.active(True)\n"
-"sta_if.scan()                             # Scan for available access points\n"
-"sta_if.connect(\"<AP_name>\", \"<password>\") # Connect to an AP\n"
-"sta_if.isconnected()                      # Check for successful connection\n"
-"# Change name/password of ESP8266's AP:\n"
-"ap_if = network.WLAN(network.AP_IF)\n"
-"ap_if.config(essid=\"<AP_NAME>\", authmode=network.AUTH_WPA_WPA2_PSK, password=\"<password>\")\n"
-"\n"
-"Control commands:\n"
-"  CTRL-A        -- on a blank line, enter raw REPL mode\n"
-"  CTRL-B        -- on a blank line, enter normal REPL mode\n"
-"  CTRL-C        -- interrupt a running program\n"
-"  CTRL-D        -- on a blank line, do a soft reset of the board\n"
-"  CTRL-E        -- on a blank line, enter paste mode\n"
-"\n"
-"For further help on a specific object, type help(obj)\n"
+    "Welcome to MicroPython!\n"
+    "\n"
+    "For online docs please visit http://docs.micropython.org/en/latest/esp8266/ .\n"
+    "For diagnostic information to include in bug reports execute 'import port_diag'.\n"
+    "\n"
+    "Basic WiFi configuration:\n"
+    "\n"
+    "import network\n"
+    "sta_if = network.WLAN(network.STA_IF); sta_if.active(True)\n"
+    "sta_if.scan()                             # Scan for available access points\n"
+    "sta_if.connect(\"<AP_name>\", \"<password>\") # Connect to an AP\n"
+    "sta_if.isconnected()                      # Check for successful connection\n"
+    "# Change name/password of ESP8266's AP:\n"
+    "ap_if = network.WLAN(network.AP_IF)\n"
+    "ap_if.config(essid=\"<AP_NAME>\", authmode=network.AUTH_WPA_WPA2_PSK, password=\"<password>\")\n"
+    "\n"
+    "Control commands:\n"
+    "  CTRL-A        -- on a blank line, enter raw REPL mode\n"
+    "  CTRL-B        -- on a blank line, enter normal REPL mode\n"
+    "  CTRL-C        -- interrupt a running program\n"
+    "  CTRL-D        -- on a blank line, do a soft reset of the board\n"
+    "  CTRL-E        -- on a blank line, enter paste mode\n"
+    "\n"
+    "For further help on a specific object, type help(obj)\n"
 ;
diff --git a/ports/esp8266/hspi.c b/ports/esp8266/hspi.c
index 554a504..cecf0b7 100644
--- a/ports/esp8266/hspi.c
+++ b/ports/esp8266/hspi.c
@@ -36,7 +36,7 @@
     spi_tx_byte_order(spi_no, SPI_BYTE_ORDER_HIGH_TO_LOW);
     spi_rx_byte_order(spi_no, SPI_BYTE_ORDER_HIGH_TO_LOW);
 
-    SET_PERI_REG_MASK(SPI_USER(spi_no), SPI_CS_SETUP|SPI_CS_HOLD);
+    SET_PERI_REG_MASK(SPI_USER(spi_no), SPI_CS_SETUP | SPI_CS_HOLD);
     CLEAR_PERI_REG_MASK(SPI_USER(spi_no), SPI_FLASH_MODE);
 }
 
@@ -84,14 +84,14 @@
     }
     if (spi_no == SPI) {
         // Set bit 8 if 80MHz sysclock required
-        WRITE_PERI_REG(PERIPHS_IO_MUX, 0x005 | (clock_div_flag<<8));
+        WRITE_PERI_REG(PERIPHS_IO_MUX, 0x005 | (clock_div_flag << 8));
         PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_CLK_U, 1);
         PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_CMD_U, 1);
         PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_DATA0_U, 1);
         PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_DATA1_U, 1);
     } else if (spi_no == HSPI) {
         // Set bit 9 if 80MHz sysclock required
-        WRITE_PERI_REG(PERIPHS_IO_MUX, 0x105 | (clock_div_flag<<9));
+        WRITE_PERI_REG(PERIPHS_IO_MUX, 0x105 | (clock_div_flag << 9));
         // GPIO12 is HSPI MISO pin (Master Data In)
         PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, 2);
         // GPIO13 is HSPI MOSI pin (Master Data Out)
@@ -117,11 +117,11 @@
         WRITE_PERI_REG(SPI_CLOCK(spi_no), SPI_CLK_EQU_SYSCLK);
     } else {
         WRITE_PERI_REG(SPI_CLOCK(spi_no),
-           (((prediv - 1) & SPI_CLKDIV_PRE) << SPI_CLKDIV_PRE_S) |
-           (((cntdiv - 1) & SPI_CLKCNT_N) << SPI_CLKCNT_N_S) |
-           (((cntdiv >> 1) & SPI_CLKCNT_H) << SPI_CLKCNT_H_S) |
-           ((0 & SPI_CLKCNT_L) << SPI_CLKCNT_L_S)
-        );
+            (((prediv - 1) & SPI_CLKDIV_PRE) << SPI_CLKDIV_PRE_S) |
+            (((cntdiv - 1) & SPI_CLKCNT_N) << SPI_CLKCNT_N_S) |
+            (((cntdiv >> 1) & SPI_CLKCNT_H) << SPI_CLKCNT_H_S) |
+            ((0 & SPI_CLKCNT_L) << SPI_CLKCNT_L_S)
+            );
     }
 }
 
@@ -185,15 +185,17 @@
 (for anything <32 bits).
 */
 uint32_t spi_transaction(uint8_t spi_no, uint8_t cmd_bits, uint16_t cmd_data,
-                         uint32_t addr_bits, uint32_t addr_data,
-                         uint32_t dout_bits, uint32_t dout_data,
-                         uint32_t din_bits, uint32_t dummy_bits) {
-    while (spi_busy(spi_no)) {};  // Wait for SPI to be ready
+    uint32_t addr_bits, uint32_t addr_data,
+    uint32_t dout_bits, uint32_t dout_data,
+    uint32_t din_bits, uint32_t dummy_bits) {
+    while (spi_busy(spi_no)) {
+    }
+    ;                             // Wait for SPI to be ready
 
 // Enable SPI Functions
     // Disable MOSI, MISO, ADDR, COMMAND, DUMMY in case previously set.
     CLEAR_PERI_REG_MASK(SPI_USER(spi_no), SPI_USR_MOSI | SPI_USR_MISO |
-                        SPI_USR_COMMAND | SPI_USR_ADDR | SPI_USR_DUMMY);
+        SPI_USR_COMMAND | SPI_USR_ADDR | SPI_USR_DUMMY);
 
     // Enable functions based on number of bits. 0 bits = disabled.
     // This is rather inefficient but allows for a very generic function.
@@ -213,25 +215,25 @@
     WRITE_PERI_REG(SPI_USER1(spi_no),
         // Number of bits in Address
         ((addr_bits - 1) & SPI_USR_ADDR_BITLEN) << SPI_USR_ADDR_BITLEN_S |
-        // Number of bits to Send
-        ((dout_bits - 1) & SPI_USR_MOSI_BITLEN) << SPI_USR_MOSI_BITLEN_S |
-        // Number of bits to receive
-        ((din_bits - 1) & SPI_USR_MISO_BITLEN) << SPI_USR_MISO_BITLEN_S |
-        // Number of Dummy bits to insert
-        ((dummy_bits - 1) & SPI_USR_DUMMY_CYCLELEN) << SPI_USR_DUMMY_CYCLELEN_S);
+            // Number of bits to Send
+                ((dout_bits - 1) & SPI_USR_MOSI_BITLEN) << SPI_USR_MOSI_BITLEN_S |
+            // Number of bits to receive
+                ((din_bits - 1) & SPI_USR_MISO_BITLEN) << SPI_USR_MISO_BITLEN_S |
+            // Number of Dummy bits to insert
+                ((dummy_bits - 1) & SPI_USR_DUMMY_CYCLELEN) << SPI_USR_DUMMY_CYCLELEN_S);
 
 // Setup Command Data
     if (cmd_bits) {
         // Enable COMMAND function in SPI module
         SET_PERI_REG_MASK(SPI_USER(spi_no), SPI_USR_COMMAND);
         // Align command data to high bits
-        uint16_t command = cmd_data << (16-cmd_bits);
+        uint16_t command = cmd_data << (16 - cmd_bits);
         // Swap byte order
-        command = ((command>>8)&0xff) | ((command<<8)&0xff00);
+        command = ((command >> 8) & 0xff) | ((command << 8) & 0xff00);
         WRITE_PERI_REG(SPI_USER2(spi_no), (
             (((cmd_bits - 1) & SPI_USR_COMMAND_BITLEN) << SPI_USR_COMMAND_BITLEN_S) |
             (command & SPI_USR_COMMAND_VALUE)
-        ));
+            ));
     }
 
 // Setup Address Data
@@ -246,42 +248,44 @@
     if (dout_bits) {
         // Enable MOSI function in SPI module
         SET_PERI_REG_MASK(SPI_USER(spi_no), SPI_USR_MOSI);
-    // Copy data to W0
-    if (READ_PERI_REG(SPI_USER(spi_no))&SPI_WR_BYTE_ORDER) {
-        WRITE_PERI_REG(SPI_W0(spi_no), dout_data << (32 - dout_bits));
-    } else {
-        uint8_t dout_extra_bits = dout_bits%8;
-
-        if (dout_extra_bits) {
-            // If your data isn't a byte multiple (8/16/24/32 bits) and you
-            // don't have SPI_WR_BYTE_ORDER set, you need this to move the
-            // non-8bit remainder to the MSBs. Not sure if there's even a use
-            // case for this, but it's here if you need it... For example,
-            // 0xDA4 12 bits without SPI_WR_BYTE_ORDER would usually be output
-            // as if it were 0x0DA4, of which 0xA4, and then 0x0 would be
-            // shifted out (first 8 bits of low byte, then 4 MSB bits of high
-            // byte - ie reverse byte order).
-            // The code below shifts it out as 0xA4 followed by 0xD as you
-            // might require.
-            WRITE_PERI_REG(SPI_W0(spi_no), (
-                (0xFFFFFFFF << (dout_bits - dout_extra_bits) & dout_data)
-                    << (8-dout_extra_bits) |
-                ((0xFFFFFFFF >> (32 - (dout_bits - dout_extra_bits)))
-                    & dout_data)
-            ));
+        // Copy data to W0
+        if (READ_PERI_REG(SPI_USER(spi_no)) & SPI_WR_BYTE_ORDER) {
+            WRITE_PERI_REG(SPI_W0(spi_no), dout_data << (32 - dout_bits));
         } else {
-            WRITE_PERI_REG(SPI_W0(spi_no), dout_data);
+            uint8_t dout_extra_bits = dout_bits % 8;
+
+            if (dout_extra_bits) {
+                // If your data isn't a byte multiple (8/16/24/32 bits) and you
+                // don't have SPI_WR_BYTE_ORDER set, you need this to move the
+                // non-8bit remainder to the MSBs. Not sure if there's even a use
+                // case for this, but it's here if you need it... For example,
+                // 0xDA4 12 bits without SPI_WR_BYTE_ORDER would usually be output
+                // as if it were 0x0DA4, of which 0xA4, and then 0x0 would be
+                // shifted out (first 8 bits of low byte, then 4 MSB bits of high
+                // byte - ie reverse byte order).
+                // The code below shifts it out as 0xA4 followed by 0xD as you
+                // might require.
+                WRITE_PERI_REG(SPI_W0(spi_no), (
+                    (0xFFFFFFFF << (dout_bits - dout_extra_bits) & dout_data)
+                        << (8 - dout_extra_bits) |
+                            ((0xFFFFFFFF >> (32 - (dout_bits - dout_extra_bits)))
+                        & dout_data)
+                    ));
+            } else {
+                WRITE_PERI_REG(SPI_W0(spi_no), dout_data);
+            }
         }
     }
-}
 
 // Begin SPI Transaction
     SET_PERI_REG_MASK(SPI_CMD(spi_no), SPI_USR);
 
 // Return DIN data
     if (din_bits) {
-        while (spi_busy(spi_no)) {}; // Wait for SPI transaction to complete
-        if (READ_PERI_REG(SPI_USER(spi_no))&SPI_RD_BYTE_ORDER) {
+        while (spi_busy(spi_no)) {
+        }
+        ;                            // Wait for SPI transaction to complete
+        if (READ_PERI_REG(SPI_USER(spi_no)) & SPI_RD_BYTE_ORDER) {
             // Assuming data in is written to MSB. TBC
             return READ_PERI_REG(SPI_W0(spi_no)) >> (32 - din_bits);
         } else {
@@ -301,19 +305,21 @@
 Just do minimal work needed to send 8 bits.
 */
 inline void spi_tx8fast(uint8_t spi_no, uint8_t dout_data) {
-    while (spi_busy(spi_no)) {};  // Wait for SPI to be ready
+    while (spi_busy(spi_no)) {
+    }
+    ;                             // Wait for SPI to be ready
 
 // Enable SPI Functions
     // Disable MOSI, MISO, ADDR, COMMAND, DUMMY in case previously set.
     CLEAR_PERI_REG_MASK(SPI_USER(spi_no), SPI_USR_MOSI | SPI_USR_MISO |
-                        SPI_USR_COMMAND | SPI_USR_ADDR | SPI_USR_DUMMY);
+        SPI_USR_COMMAND | SPI_USR_ADDR | SPI_USR_DUMMY);
 
 // Setup Bitlengths
     WRITE_PERI_REG(SPI_USER1(spi_no),
         // Number of bits to Send
         ((8 - 1) & SPI_USR_MOSI_BITLEN) << SPI_USR_MOSI_BITLEN_S |
-        // Number of bits to receive
-        ((8 - 1) & SPI_USR_MISO_BITLEN) << SPI_USR_MISO_BITLEN_S);
+            // Number of bits to receive
+                ((8 - 1) & SPI_USR_MISO_BITLEN) << SPI_USR_MISO_BITLEN_S);
 
 
 // Setup DOUT data
diff --git a/ports/esp8266/hspi.h b/ports/esp8266/hspi.h
index c68366e..aae9840 100644
--- a/ports/esp8266/hspi.h
+++ b/ports/esp8266/hspi.h
@@ -58,13 +58,13 @@
 void spi_tx_byte_order(uint8_t spi_no, uint8_t byte_order);
 void spi_rx_byte_order(uint8_t spi_no, uint8_t byte_order);
 uint32_t spi_transaction(uint8_t spi_no, uint8_t cmd_bits, uint16_t cmd_data,
-                         uint32_t addr_bits, uint32_t addr_data,
-                         uint32_t dout_bits, uint32_t dout_data,
-                         uint32_t din_bits, uint32_t dummy_bits);
+    uint32_t addr_bits, uint32_t addr_data,
+    uint32_t dout_bits, uint32_t dout_data,
+    uint32_t din_bits, uint32_t dummy_bits);
 void spi_tx8fast(uint8_t spi_no, uint8_t dout_data);
 
 // Expansion Macros
-#define spi_busy(spi_no) READ_PERI_REG(SPI_CMD(spi_no))&SPI_USR
+#define spi_busy(spi_no) READ_PERI_REG(SPI_CMD(spi_no)) & SPI_USR
 
 #define spi_txd(spi_no, bits, data) spi_transaction(spi_no, 0, 0, 0, 0, bits, (uint32_t) data, 0, 0)
 #define spi_tx8(spi_no, data)       spi_transaction(spi_no, 0, 0, 0, 0, 8,    (uint32_t) data, 0, 0)
diff --git a/ports/esp8266/lexerstr32.c b/ports/esp8266/lexerstr32.c
index 6fb84bb..a921efb 100644
--- a/ports/esp8266/lexerstr32.c
+++ b/ports/esp8266/lexerstr32.c
@@ -36,7 +36,7 @@
 } mp_lexer_str32_buf_t;
 
 STATIC mp_uint_t str32_buf_next_byte(void *sb_in) {
-    mp_lexer_str32_buf_t *sb = (mp_lexer_str32_buf_t*)sb_in;
+    mp_lexer_str32_buf_t *sb = (mp_lexer_str32_buf_t *)sb_in;
     byte c = sb->val & 0xff;
     if (c == 0) {
         return MP_READER_EOF;
@@ -53,14 +53,14 @@
 }
 
 STATIC void str32_buf_free(void *sb_in) {
-    mp_lexer_str32_buf_t *sb = (mp_lexer_str32_buf_t*)sb_in;
+    mp_lexer_str32_buf_t *sb = (mp_lexer_str32_buf_t *)sb_in;
     m_del_obj(mp_lexer_str32_buf_t, sb);
 }
 
 mp_lexer_t *mp_lexer_new_from_str32(qstr src_name, const char *str, mp_uint_t len, mp_uint_t free_len) {
     mp_lexer_str32_buf_t *sb = m_new_obj(mp_lexer_str32_buf_t);
     sb->byte_off = (uint32_t)str & 3;
-    sb->src_cur = (uint32_t*)(str - sb->byte_off);
+    sb->src_cur = (uint32_t *)(str - sb->byte_off);
     sb->val = *sb->src_cur++ >> sb->byte_off * 8;
     mp_reader_t reader = {sb, str32_buf_next_byte, str32_buf_free};
     return mp_lexer_new(src_name, reader);
diff --git a/ports/esp8266/machine_adc.c b/ports/esp8266/machine_adc.c
index 2318239..b0b458a 100644
--- a/ports/esp8266/machine_adc.c
+++ b/ports/esp8266/machine_adc.c
@@ -59,12 +59,12 @@
     mp_int_t chn = mp_obj_get_int(args[0]);
 
     switch (chn) {
-    case 0:
-        return &machine_adc_adc;
-    case 1:
-        return &machine_adc_vdd3;
-    default:
-        mp_raise_msg_varg(&mp_type_ValueError, "ADC(%d) doesn't exist", chn);
+        case 0:
+            return &machine_adc_adc;
+        case 1:
+            return &machine_adc_vdd3;
+        default:
+            mp_raise_msg_varg(&mp_type_ValueError, "ADC(%d) doesn't exist", chn);
     }
 }
 
@@ -94,5 +94,5 @@
     .name = MP_QSTR_ADC,
     .print = machine_adc_print,
     .make_new = machine_adc_make_new,
-    .locals_dict = (mp_obj_dict_t*)&machine_adc_locals_dict,
+    .locals_dict = (mp_obj_dict_t *)&machine_adc_locals_dict,
 };
diff --git a/ports/esp8266/machine_hspi.c b/ports/esp8266/machine_hspi.c
index 07770c8..11c95a3 100644
--- a/ports/esp8266/machine_hspi.c
+++ b/ports/esp8266/machine_hspi.c
@@ -101,7 +101,7 @@
 }
 
 STATIC void machine_hspi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
-    machine_hspi_obj_t *self = (machine_hspi_obj_t*)self_in;
+    machine_hspi_obj_t *self = (machine_hspi_obj_t *)self_in;
 
     enum { ARG_baudrate, ARG_polarity, ARG_phase };
     static const mp_arg_t allowed_args[] = {
@@ -111,7 +111,7 @@
     };
     mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
     mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args),
-                     allowed_args, args);
+        allowed_args, args);
 
     if (args[ARG_baudrate].u_int != -1) {
         self->baudrate = args[ARG_baudrate].u_int;
@@ -143,10 +143,10 @@
     spi_tx_byte_order(HSPI, SPI_BYTE_ORDER_HIGH_TO_LOW);
     spi_rx_byte_order(HSPI, SPI_BYTE_ORDER_HIGH_TO_LOW);
     CLEAR_PERI_REG_MASK(SPI_USER(HSPI), SPI_FLASH_MODE | SPI_USR_MISO |
-                        SPI_USR_ADDR | SPI_USR_COMMAND | SPI_USR_DUMMY);
+        SPI_USR_ADDR | SPI_USR_COMMAND | SPI_USR_DUMMY);
     // Clear Dual or Quad lines transmission mode
     CLEAR_PERI_REG_MASK(SPI_CTRL(HSPI), SPI_QIO_MODE | SPI_DIO_MODE |
-                        SPI_DOUT_MODE | SPI_QOUT_MODE);
+        SPI_DOUT_MODE | SPI_QOUT_MODE);
     spi_mode(HSPI, self->phase, self->polarity);
 }
 
@@ -165,7 +165,7 @@
     self->phase = 0;
     mp_map_t kw_args;
     mp_map_init_fixed_table(&kw_args, n_kw, args + n_args);
-    machine_hspi_init((mp_obj_base_t*)self, n_args - 1, args + 1, &kw_args);
+    machine_hspi_init((mp_obj_base_t *)self, n_args - 1, args + 1, &kw_args);
     return MP_OBJ_FROM_PTR(self);
 }
 
@@ -180,7 +180,7 @@
     .print = machine_hspi_print,
     .make_new = mp_machine_spi_make_new, // delegate to master constructor
     .protocol = &machine_hspi_p,
-    .locals_dict = (mp_obj_dict_t*)&mp_machine_spi_locals_dict,
+    .locals_dict = (mp_obj_dict_t *)&mp_machine_spi_locals_dict,
 };
 
 #endif // MICROPY_PY_MACHINE_SPI
diff --git a/ports/esp8266/machine_pin.c b/ports/esp8266/machine_pin.c
index 1200aa9..c77bd55 100644
--- a/ports/esp8266/machine_pin.c
+++ b/ports/esp8266/machine_pin.c
@@ -43,8 +43,8 @@
     GPIO_PIN_INT_TYPE_GET(GPIO_REG_READ(GPIO_PIN_ADDR(phys_port)))
 #define SET_TRIGGER(phys_port, trig) \
     (GPIO_REG_WRITE(GPIO_PIN_ADDR(phys_port), \
-        (GPIO_REG_READ(GPIO_PIN_ADDR(phys_port)) & ~GPIO_PIN_INT_TYPE_MASK) \
-        | GPIO_PIN_INT_TYPE_SET(trig))) \
+    (GPIO_REG_READ(GPIO_PIN_ADDR(phys_port)) & ~GPIO_PIN_INT_TYPE_MASK) \
+    | GPIO_PIN_INT_TYPE_SET(trig))) \
 
 #define GPIO_MODE_INPUT (0)
 #define GPIO_MODE_OUTPUT (1)
@@ -315,7 +315,7 @@
     int wanted_pin = mp_obj_get_int(args[0]);
     pyb_pin_obj_t *pin = NULL;
     if (0 <= wanted_pin && wanted_pin < MP_ARRAY_SIZE(pyb_pin_obj)) {
-        pin = (pyb_pin_obj_t*)&pyb_pin_obj[wanted_pin];
+        pin = (pyb_pin_obj_t *)&pyb_pin_obj[wanted_pin];
     }
     if (pin == NULL || pin->base.type == NULL) {
         mp_raise_ValueError("invalid pin");
@@ -458,7 +458,7 @@
     .make_new = mp_pin_make_new,
     .call = pyb_pin_call,
     .protocol = &pin_pin_p,
-    .locals_dict = (mp_obj_dict_t*)&pyb_pin_locals_dict,
+    .locals_dict = (mp_obj_dict_t *)&pyb_pin_locals_dict,
 };
 
 /******************************************************************************/
@@ -514,5 +514,5 @@
     { &mp_type_type },
     .name = MP_QSTR_IRQ,
     .call = pin_irq_call,
-    .locals_dict = (mp_obj_dict_t*)&pin_irq_locals_dict,
+    .locals_dict = (mp_obj_dict_t *)&pin_irq_locals_dict,
 };
diff --git a/ports/esp8266/machine_pwm.c b/ports/esp8266/machine_pwm.c
index 6bf8fc9..5325580 100644
--- a/ports/esp8266/machine_pwm.c
+++ b/ports/esp8266/machine_pwm.c
@@ -166,5 +166,5 @@
     .name = MP_QSTR_PWM,
     .print = pyb_pwm_print,
     .make_new = pyb_pwm_make_new,
-    .locals_dict = (mp_obj_dict_t*)&pyb_pwm_locals_dict,
+    .locals_dict = (mp_obj_dict_t *)&pyb_pwm_locals_dict,
 };
diff --git a/ports/esp8266/machine_rtc.c b/ports/esp8266/machine_rtc.c
index bbfc172..3df2dfc 100644
--- a/ports/esp8266/machine_rtc.c
+++ b/ports/esp8266/machine_rtc.c
@@ -266,5 +266,5 @@
     { &mp_type_type },
     .name = MP_QSTR_RTC,
     .make_new = pyb_rtc_make_new,
-    .locals_dict = (mp_obj_dict_t*)&pyb_rtc_locals_dict,
+    .locals_dict = (mp_obj_dict_t *)&pyb_rtc_locals_dict,
 };
diff --git a/ports/esp8266/machine_uart.c b/ports/esp8266/machine_uart.c
index e4f77fb..735e01b 100644
--- a/ports/esp8266/machine_uart.c
+++ b/ports/esp8266/machine_uart.c
@@ -268,7 +268,7 @@
         *buf++ = uart_rx_char();
         if (--size == 0 || !uart_rx_wait(self->timeout_char * 1000)) {
             // return number of bytes read
-            return buf - (uint8_t*)buf_in;
+            return buf - (uint8_t *)buf_in;
         }
     }
 }
@@ -328,5 +328,5 @@
     .getiter = mp_identity_getiter,
     .iternext = mp_stream_unbuffered_iter,
     .protocol = &uart_stream_p,
-    .locals_dict = (mp_obj_dict_t*)&pyb_uart_locals_dict,
+    .locals_dict = (mp_obj_dict_t *)&pyb_uart_locals_dict,
 };
diff --git a/ports/esp8266/machine_wdt.c b/ports/esp8266/machine_wdt.c
index fad0b2e..9411e31 100644
--- a/ports/esp8266/machine_wdt.c
+++ b/ports/esp8266/machine_wdt.c
@@ -49,12 +49,12 @@
     }
 
     switch (id) {
-    case 0:
-        ets_loop_dont_feed_sw_wdt = 1;
-        system_soft_wdt_feed();
-        return &wdt_default;
-    default:
-        mp_raise_ValueError(NULL);
+        case 0:
+            ets_loop_dont_feed_sw_wdt = 1;
+            system_soft_wdt_feed();
+            return &wdt_default;
+        default:
+            mp_raise_ValueError(NULL);
     }
 }
 
@@ -82,5 +82,5 @@
     { &mp_type_type },
     .name = MP_QSTR_WDT,
     .make_new = machine_wdt_make_new,
-    .locals_dict = (mp_obj_dict_t*)&machine_wdt_locals_dict,
+    .locals_dict = (mp_obj_dict_t *)&machine_wdt_locals_dict,
 };
diff --git a/ports/esp8266/main.c b/ports/esp8266/main.c
index 8bfb2a0..aff5936 100644
--- a/ports/esp8266/main.c
+++ b/ports/esp8266/main.c
@@ -47,7 +47,7 @@
 STATIC char heap[38 * 1024];
 
 STATIC void mp_reset(void) {
-    mp_stack_set_top((void*)0x40000000);
+    mp_stack_set_top((void *)0x40000000);
     mp_stack_set_limit(8192);
     mp_hal_init();
     gc_init(heap, heap + sizeof(heap));
diff --git a/ports/esp8266/makeimg.py b/ports/esp8266/makeimg.py
index 091854f..a81b2d0 100644
--- a/ports/esp8266/makeimg.py
+++ b/ports/esp8266/makeimg.py
@@ -8,33 +8,33 @@
 
 md5 = hashlib.md5()
 
-with open(sys.argv[3], 'wb') as fout:
+with open(sys.argv[3], "wb") as fout:
 
-    with open(sys.argv[1], 'rb') as f:
+    with open(sys.argv[1], "rb") as f:
         data_flash = f.read()
         fout.write(data_flash)
         # First 4 bytes include flash size, etc. which may be changed
         # by esptool.py, etc.
         md5.update(data_flash[4:])
-        print('flash    ', len(data_flash))
+        print("flash    ", len(data_flash))
 
-    with open(sys.argv[2], 'rb') as f:
+    with open(sys.argv[2], "rb") as f:
         data_rom = f.read()
 
-    pad = b'\xff' * (SEGS_MAX_SIZE - len(data_flash))
+    pad = b"\xff" * (SEGS_MAX_SIZE - len(data_flash))
     assert len(pad) >= 4
     fout.write(pad[:-4])
     md5.update(pad[:-4])
     len_data = struct.pack("I", SEGS_MAX_SIZE + len(data_rom))
     fout.write(len_data)
     md5.update(len_data)
-    print('padding  ', len(pad))
+    print("padding  ", len(pad))
 
     fout.write(data_rom)
     md5.update(data_rom)
-    print('irom0text', len(data_rom))
+    print("irom0text", len(data_rom))
 
     fout.write(md5.digest())
 
-    print('total    ', SEGS_MAX_SIZE + len(data_rom))
-    print('md5      ', md5.hexdigest())
+    print("total    ", SEGS_MAX_SIZE + len(data_rom))
+    print("md5      ", md5.hexdigest())
diff --git a/ports/esp8266/modesp.c b/ports/esp8266/modesp.c
index 6f937e0..95566cd 100644
--- a/ports/esp8266/modesp.c
+++ b/ports/esp8266/modesp.c
@@ -101,7 +101,7 @@
     }
 
     // We know that allocation will be 4-byte aligned for sure
-    SpiFlashOpResult res = spi_flash_read(offset, (uint32_t*)buf, len);
+    SpiFlashOpResult res = spi_flash_read(offset, (uint32_t *)buf, len);
     if (res == SPI_FLASH_RESULT_OK) {
         if (alloc_buf) {
             return mp_obj_new_bytes(buf, len);
@@ -148,7 +148,7 @@
     extern char flashchip;
     // For SDK 1.5.2, either address has shifted and not mirrored in
     // eagle.rom.addr.v6.ld, or extra initial member was added.
-    SpiFlashChip *flash = (SpiFlashChip*)(&flashchip + 4);
+    SpiFlashChip *flash = (SpiFlashChip *)(&flashchip + 4);
     #if 0
     printf("deviceId: %x\n", flash->deviceId);
     printf("chip_size: %u\n", flash->chip_size);
@@ -163,7 +163,7 @@
 
 // If there's just 1 loadable segment at the start of flash,
 // we assume there's a yaota8266 bootloader.
-#define IS_OTA_FIRMWARE() ((*(uint32_t*)0x40200000 & 0xff00) == 0x100)
+#define IS_OTA_FIRMWARE() ((*(uint32_t *)0x40200000 & 0xff00) == 0x100)
 
 extern byte _firmware_size[];
 
@@ -174,13 +174,13 @@
 
 STATIC mp_obj_t esp_check_fw(void) {
     MD5_CTX ctx;
-    char *fw_start = (char*)0x40200000;
+    char *fw_start = (char *)0x40200000;
     if (IS_OTA_FIRMWARE()) {
         // Skip yaota8266 bootloader
         fw_start += 0x3c000;
     }
 
-    uint32_t size = *(uint32_t*)(fw_start + 0x8ffc);
+    uint32_t size = *(uint32_t *)(fw_start + 0x8ffc);
     printf("size: %d\n", size);
     if (size > 1024 * 1024) {
         printf("Invalid size\n");
@@ -204,7 +204,7 @@
     mp_buffer_info_t bufinfo;
     mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ);
     esp_neopixel_write(mp_obj_get_pin_obj(pin)->phys_port,
-        (uint8_t*)bufinfo.buf, bufinfo.len, mp_obj_is_true(is800k));
+        (uint8_t *)bufinfo.buf, bufinfo.len, mp_obj_is_true(is800k));
     return mp_const_none;
 }
 STATIC MP_DEFINE_CONST_FUN_OBJ_3(esp_neopixel_write_obj, esp_neopixel_write_);
@@ -215,7 +215,7 @@
     mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ);
     esp_apa102_write(mp_obj_get_pin_obj(clockPin)->phys_port,
         mp_obj_get_pin_obj(dataPin)->phys_port,
-        (uint8_t*)bufinfo.buf, bufinfo.len);
+        (uint8_t *)bufinfo.buf, bufinfo.len);
     return mp_const_none;
 }
 STATIC MP_DEFINE_CONST_FUN_OBJ_3(esp_apa102_write_obj, esp_apa102_write_);
@@ -238,7 +238,7 @@
 STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_malloc_obj, esp_malloc);
 
 STATIC mp_obj_t esp_free(mp_obj_t addr_in) {
-    os_free((void*)mp_obj_get_int(addr_in));
+    os_free((void *)mp_obj_get_int(addr_in));
     return mp_const_none;
 }
 STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_free_obj, esp_free);
@@ -294,9 +294,9 @@
 
     void *dest;
     if (esp_native_code_location == ESP_NATIVE_CODE_IRAM1) {
-        dest = (void*)esp_native_code_cur;
+        dest = (void *)esp_native_code_cur;
     } else {
-        dest = (void*)(FLASH_START + esp_native_code_cur);
+        dest = (void *)(FLASH_START + esp_native_code_cur);
     }
     if (reloc) {
         mp_native_relocate(reloc, buf, (uintptr_t)dest);
@@ -381,16 +381,16 @@
     { MP_ROM_QSTR(MP_QSTR_set_native_code_location), MP_ROM_PTR(&esp_set_native_code_location_obj) },
     #endif
 
-#if MODESP_INCLUDE_CONSTANTS
+    #if MODESP_INCLUDE_CONSTANTS
     { MP_ROM_QSTR(MP_QSTR_SLEEP_NONE), MP_ROM_INT(NONE_SLEEP_T) },
     { MP_ROM_QSTR(MP_QSTR_SLEEP_LIGHT), MP_ROM_INT(LIGHT_SLEEP_T) },
     { MP_ROM_QSTR(MP_QSTR_SLEEP_MODEM), MP_ROM_INT(MODEM_SLEEP_T) },
-#endif
+    #endif
 };
 
 STATIC MP_DEFINE_CONST_DICT(esp_module_globals, esp_module_globals_table);
 
 const mp_obj_module_t esp_module = {
     .base = { &mp_type_module },
-    .globals = (mp_obj_dict_t*)&esp_module_globals,
+    .globals = (mp_obj_dict_t *)&esp_module_globals,
 };
diff --git a/ports/esp8266/modmachine.c b/ports/esp8266/modmachine.c
index 35d4918..e6be0c1 100644
--- a/ports/esp8266/modmachine.c
+++ b/ports/esp8266/modmachine.c
@@ -84,13 +84,13 @@
 
 STATIC mp_obj_t machine_unique_id(void) {
     uint32_t id = system_get_chip_id();
-    return mp_obj_new_bytes((byte*)&id, sizeof(id));
+    return mp_obj_new_bytes((byte *)&id, sizeof(id));
 }
 STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_unique_id_obj, machine_unique_id);
 
 STATIC mp_obj_t machine_idle(void) {
     uint32_t t = mp_hal_ticks_cpu();
-    asm("waiti 0");
+    asm ("waiti 0");
     t = mp_hal_ticks_cpu() - t;
     ets_event_poll(); // handle any events after possibly a long wait (eg feed WDT)
     return MP_OBJ_NEW_SMALL_INT(t);
@@ -112,7 +112,7 @@
         ets_event_poll();
         if (wifi_mode == NULL_MODE) {
             // Can only idle if the wifi is off
-            asm("waiti 0");
+            asm ("waiti 0");
         }
     }
     return mp_const_none;
@@ -256,11 +256,11 @@
         { MP_QSTR_callback,     MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
         { MP_QSTR_period,       MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0xffffffff} },
         { MP_QSTR_tick_hz,      MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1000} },
-#if MICROPY_PY_BUILTINS_FLOAT
+        #if MICROPY_PY_BUILTINS_FLOAT
         { MP_QSTR_freq,         MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
-#else
+        #else
         { MP_QSTR_freq,         MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0xffffffff} },
-#endif
+        #endif
     };
 
     // parse args
@@ -272,7 +272,7 @@
     os_timer_disarm(&self->timer);
     os_timer_setfn(&self->timer, esp_timer_cb, self);
 
-#if MICROPY_PY_BUILTINS_FLOAT
+    #if MICROPY_PY_BUILTINS_FLOAT
     if (args[ARG_freq].u_obj != mp_const_none) {
         mp_float_t freq = mp_obj_get_float(args[ARG_freq].u_obj);
         if (freq < 0.001) {
@@ -281,11 +281,11 @@
             esp_timer_arm_us(self, (mp_int_t)(1000000 / freq), args[ARG_mode].u_int);
         }
     }
-#else
+    #else
     if (args[ARG_freq].u_int != 0xffffffff) {
         esp_timer_arm_us(self, 1000000 / args[ARG_freq].u_int, args[ARG_mode].u_int);
     }
-#endif
+    #endif
     else {
         mp_int_t period = args[ARG_period].u_int;
         mp_int_t hz = args[ARG_tick_hz].u_int;
@@ -333,7 +333,7 @@
     .name = MP_QSTR_Timer,
     .print = esp_timer_print,
     .make_new = esp_timer_make_new,
-    .locals_dict = (mp_obj_dict_t*)&esp_timer_locals_dict,
+    .locals_dict = (mp_obj_dict_t *)&esp_timer_locals_dict,
 };
 
 // this bit is unused in the Xtensa PS register
@@ -434,7 +434,7 @@
 
 const mp_obj_module_t mp_module_machine = {
     .base = { &mp_type_module },
-    .globals = (mp_obj_dict_t*)&machine_module_globals,
+    .globals = (mp_obj_dict_t *)&machine_module_globals,
 };
 
 #endif // MICROPY_PY_MACHINE
diff --git a/ports/esp8266/modnetwork.c b/ports/esp8266/modnetwork.c
index 6bdbe6e..ef3e02e 100644
--- a/ports/esp8266/modnetwork.c
+++ b/ports/esp8266/modnetwork.c
@@ -204,7 +204,7 @@
                 // but is present in SDK headers since 1.4.0
                 t->items[0] = mp_obj_new_bytes(bs->ssid, bs->ssid_len);
                 #else
-                t->items[0] = mp_obj_new_bytes(bs->ssid, strlen((char*)bs->ssid));
+                t->items[0] = mp_obj_new_bytes(bs->ssid, strlen((char *)bs->ssid));
                 #endif
                 t->items[1] = mp_obj_new_bytes(bs->bssid, sizeof(bs->bssid));
                 t->items[2] = MP_OBJ_NEW_SMALL_INT(bs->channel);
@@ -280,10 +280,10 @@
         // get
         dns_addr = dns_getserver(0);
         mp_obj_t tuple[4] = {
-            netutils_format_ipv4_addr((uint8_t*)&info.ip, NETUTILS_BIG),
-            netutils_format_ipv4_addr((uint8_t*)&info.netmask, NETUTILS_BIG),
-            netutils_format_ipv4_addr((uint8_t*)&info.gw, NETUTILS_BIG),
-            netutils_format_ipv4_addr((uint8_t*)&dns_addr, NETUTILS_BIG),
+            netutils_format_ipv4_addr((uint8_t *)&info.ip, NETUTILS_BIG),
+            netutils_format_ipv4_addr((uint8_t *)&info.netmask, NETUTILS_BIG),
+            netutils_format_ipv4_addr((uint8_t *)&info.gw, NETUTILS_BIG),
+            netutils_format_ipv4_addr((uint8_t *)&dns_addr, NETUTILS_BIG),
         };
         return mp_obj_new_tuple(4, tuple);
     } else {
@@ -291,19 +291,19 @@
         mp_obj_t *items;
         bool restart_dhcp_server = false;
         mp_obj_get_array_fixed_n(args[1], 4, &items);
-        netutils_parse_ipv4_addr(items[0], (void*)&info.ip, NETUTILS_BIG);
+        netutils_parse_ipv4_addr(items[0], (void *)&info.ip, NETUTILS_BIG);
         if (mp_obj_is_integer(items[1])) {
             // allow numeric netmask, i.e.:
             // 24 -> 255.255.255.0
             // 16 -> 255.255.0.0
             // etc...
-            uint32_t* m = (uint32_t*)&info.netmask;
+            uint32_t *m = (uint32_t *)&info.netmask;
             *m = htonl(0xffffffff << (32 - mp_obj_get_int(items[1])));
         } else {
-            netutils_parse_ipv4_addr(items[1], (void*)&info.netmask, NETUTILS_BIG);
+            netutils_parse_ipv4_addr(items[1], (void *)&info.netmask, NETUTILS_BIG);
         }
-        netutils_parse_ipv4_addr(items[2], (void*)&info.gw, NETUTILS_BIG);
-        netutils_parse_ipv4_addr(items[3], (void*)&dns_addr, NETUTILS_BIG);
+        netutils_parse_ipv4_addr(items[2], (void *)&info.gw, NETUTILS_BIG);
+        netutils_parse_ipv4_addr(items[3], (void *)&dns_addr, NETUTILS_BIG);
         // To set a static IP we have to disable DHCP first
         if (self->if_id == STATION_IF) {
             wifi_station_dhcpc_stop();
@@ -312,7 +312,7 @@
             wifi_softap_dhcps_stop();
         }
         if (!wifi_set_ip_info(self->if_id, &info)) {
-          mp_raise_msg(&mp_type_OSError, "wifi_set_ip_info() failed");
+            mp_raise_msg(&mp_type_OSError, "wifi_set_ip_info() failed");
         }
         dns_setserver(0, &dns_addr);
         if (restart_dhcp_server) {
@@ -394,14 +394,14 @@
                         req_if = STATION_IF;
                         if (self->if_id == STATION_IF) {
                             const char *s = mp_obj_str_get_str(kwargs->table[i].value);
-                            wifi_station_set_hostname((char*)s);
+                            wifi_station_set_hostname((char *)s);
                         }
                         break;
                     }
                     default:
                         goto unknown;
                 }
-                #undef QS
+#undef QS
             }
         }
 
@@ -436,9 +436,9 @@
         }
         case MP_QSTR_essid:
             if (self->if_id == STATION_IF) {
-                val = mp_obj_new_str((char*)cfg.sta.ssid, strlen((char*)cfg.sta.ssid));
+                val = mp_obj_new_str((char *)cfg.sta.ssid, strlen((char *)cfg.sta.ssid));
             } else {
-                val = mp_obj_new_str((char*)cfg.ap.ssid, cfg.ap.ssid_len);
+                val = mp_obj_new_str((char *)cfg.ap.ssid, cfg.ap.ssid_len);
             }
             break;
         case MP_QSTR_hidden:
@@ -455,7 +455,7 @@
             break;
         case MP_QSTR_dhcp_hostname: {
             req_if = STATION_IF;
-            char* s = wifi_station_get_hostname();
+            char *s = wifi_station_get_hostname();
             if (s == NULL) {
                 val = MP_OBJ_NEW_QSTR(MP_QSTR_);
             } else {
@@ -495,7 +495,7 @@
 const mp_obj_type_t wlan_if_type = {
     { &mp_type_type },
     .name = MP_QSTR_WLAN,
-    .locals_dict = (mp_obj_dict_t*)&wlan_if_locals_dict,
+    .locals_dict = (mp_obj_dict_t *)&wlan_if_locals_dict,
 };
 
 STATIC mp_obj_t esp_phy_mode(size_t n_args, const mp_obj_t *args) {
@@ -513,7 +513,7 @@
     { MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&get_wlan_obj) },
     { MP_ROM_QSTR(MP_QSTR_phy_mode), MP_ROM_PTR(&esp_phy_mode_obj) },
 
-#if MODNETWORK_INCLUDE_CONSTANTS
+    #if MODNETWORK_INCLUDE_CONSTANTS
     { MP_ROM_QSTR(MP_QSTR_STA_IF), MP_ROM_INT(STATION_IF)},
     { MP_ROM_QSTR(MP_QSTR_AP_IF), MP_ROM_INT(SOFTAP_IF)},
 
@@ -533,12 +533,12 @@
     { MP_ROM_QSTR(MP_QSTR_AUTH_WPA_PSK), MP_ROM_INT(AUTH_WPA_PSK) },
     { MP_ROM_QSTR(MP_QSTR_AUTH_WPA2_PSK), MP_ROM_INT(AUTH_WPA2_PSK) },
     { MP_ROM_QSTR(MP_QSTR_AUTH_WPA_WPA2_PSK), MP_ROM_INT(AUTH_WPA_WPA2_PSK) },
-#endif
+    #endif
 };
 
 STATIC MP_DEFINE_CONST_DICT(mp_module_network_globals, mp_module_network_globals_table);
 
 const mp_obj_module_t network_module = {
     .base = { &mp_type_module },
-    .globals = (mp_obj_dict_t*)&mp_module_network_globals,
+    .globals = (mp_obj_dict_t *)&mp_module_network_globals,
 };
diff --git a/ports/esp8266/modules/_boot.py b/ports/esp8266/modules/_boot.py
index 4c2aa87..1f77d88 100644
--- a/ports/esp8266/modules/_boot.py
+++ b/ports/esp8266/modules/_boot.py
@@ -1,13 +1,15 @@
 import gc
+
 gc.threshold((gc.mem_free() + gc.mem_alloc()) // 4)
 import uos
 from flashbdev import bdev
 
 if bdev:
     try:
-        uos.mount(bdev, '/')
+        uos.mount(bdev, "/")
     except:
         import inisetup
+
         inisetup.setup()
 
 gc.collect()
diff --git a/ports/esp8266/modules/flashbdev.py b/ports/esp8266/modules/flashbdev.py
index 4273b26..404cf36 100644
--- a/ports/esp8266/modules/flashbdev.py
+++ b/ports/esp8266/modules/flashbdev.py
@@ -1,29 +1,30 @@
 import esp
 
+
 class FlashBdev:
 
     SEC_SIZE = 4096
     RESERVED_SECS = 1
     START_SEC = esp.flash_user_start() // SEC_SIZE + RESERVED_SECS
-    NUM_BLK = 0x6b - RESERVED_SECS
+    NUM_BLK = 0x6B - RESERVED_SECS
 
     def __init__(self, blocks=NUM_BLK):
         self.blocks = blocks
 
     def readblocks(self, n, buf, off=0):
-        #print("readblocks(%s, %x(%d), %d)" % (n, id(buf), len(buf), off))
+        # print("readblocks(%s, %x(%d), %d)" % (n, id(buf), len(buf), off))
         esp.flash_read((n + self.START_SEC) * self.SEC_SIZE + off, buf)
 
     def writeblocks(self, n, buf, off=None):
-        #print("writeblocks(%s, %x(%d), %d)" % (n, id(buf), len(buf), off))
-        #assert len(buf) <= self.SEC_SIZE, len(buf)
+        # print("writeblocks(%s, %x(%d), %d)" % (n, id(buf), len(buf), off))
+        # assert len(buf) <= self.SEC_SIZE, len(buf)
         if off is None:
             esp.flash_erase(n + self.START_SEC)
             off = 0
         esp.flash_write((n + self.START_SEC) * self.SEC_SIZE + off, buf)
 
     def ioctl(self, op, arg):
-        #print("ioctl(%d, %r)" % (op, arg))
+        # print("ioctl(%d, %r)" % (op, arg))
         if op == 4:  # MP_BLOCKDEV_IOCTL_BLOCK_COUNT
             return self.blocks
         if op == 5:  # MP_BLOCKDEV_IOCTL_BLOCK_SIZE
@@ -32,8 +33,9 @@
             esp.flash_erase(arg + self.START_SEC)
             return 0
 
+
 size = esp.flash_size()
-if size < 1024*1024:
+if size < 1024 * 1024:
     bdev = None
 else:
     # 20K at the flash end is reserved for SDK params storage
diff --git a/ports/esp8266/modules/inisetup.py b/ports/esp8266/modules/inisetup.py
index cb4fc04..1bbc3d0 100644
--- a/ports/esp8266/modules/inisetup.py
+++ b/ports/esp8266/modules/inisetup.py
@@ -2,45 +2,55 @@
 import network
 from flashbdev import bdev
 
+
 def wifi():
     import ubinascii
+
     ap_if = network.WLAN(network.AP_IF)
     essid = b"MicroPython-%s" % ubinascii.hexlify(ap_if.config("mac")[-3:])
     ap_if.config(essid=essid, authmode=network.AUTH_WPA_WPA2_PSK, password=b"micropythoN")
 
+
 def check_bootsec():
     buf = bytearray(bdev.SEC_SIZE)
     bdev.readblocks(0, buf)
     empty = True
     for b in buf:
-        if b != 0xff:
+        if b != 0xFF:
             empty = False
             break
     if empty:
         return True
     fs_corrupted()
 
+
 def fs_corrupted():
     import time
+
     while 1:
-        print("""\
+        print(
+            """\
 The FAT filesystem starting at sector %d with size %d sectors appears to
 be corrupted. If you had important data there, you may want to make a flash
 snapshot to try to recover it. Otherwise, perform factory reprogramming
 of MicroPython firmware (completely erase flash, followed by firmware
 programming).
-""" % (bdev.START_SEC, bdev.blocks))
+"""
+            % (bdev.START_SEC, bdev.blocks)
+        )
         time.sleep(3)
 
+
 def setup():
     check_bootsec()
     print("Performing initial setup")
     wifi()
     uos.VfsFat.mkfs(bdev)
     vfs = uos.VfsFat(bdev)
-    uos.mount(vfs, '/')
+    uos.mount(vfs, "/")
     with open("boot.py", "w") as f:
-        f.write("""\
+        f.write(
+            """\
 # This file is executed on every boot (including wake-boot from deepsleep)
 #import esp
 #esp.osdebug(None)
@@ -50,5 +60,6 @@
 #import webrepl
 #webrepl.start()
 gc.collect()
-""")
+"""
+        )
     return vfs
diff --git a/ports/esp8266/modules/neopixel.py b/ports/esp8266/modules/neopixel.py
index b13424d..be56ed1 100644
--- a/ports/esp8266/modules/neopixel.py
+++ b/ports/esp8266/modules/neopixel.py
@@ -21,8 +21,7 @@
 
     def __getitem__(self, index):
         offset = index * self.bpp
-        return tuple(self.buf[offset + self.ORDER[i]]
-                     for i in range(self.bpp))
+        return tuple(self.buf[offset + self.ORDER[i]] for i in range(self.bpp))
 
     def fill(self, color):
         for i in range(self.n):
diff --git a/ports/esp8266/modules/ntptime.py b/ports/esp8266/modules/ntptime.py
index 0f51210..92ae6ab 100644
--- a/ports/esp8266/modules/ntptime.py
+++ b/ports/esp8266/modules/ntptime.py
@@ -13,9 +13,10 @@
 # The NTP host can be configured at runtime by doing: ntptime.host = 'myhost.org'
 host = "pool.ntp.org"
 
+
 def time():
     NTP_QUERY = bytearray(48)
-    NTP_QUERY[0] = 0x1b
+    NTP_QUERY[0] = 0x1B
     addr = socket.getaddrinfo(host, 123)[0][-1]
     s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
     try:
@@ -27,11 +28,13 @@
     val = struct.unpack("!I", msg[40:44])[0]
     return val - NTP_DELTA
 
+
 # There's currently no timezone support in MicroPython, so
 # utime.localtime() will return UTC time (as if it was .gmtime())
 def settime():
     t = time()
     import machine
     import utime
+
     tm = utime.localtime(t)
     machine.RTC().datetime((tm[0], tm[1], tm[2], tm[6] + 1, tm[3], tm[4], tm[5], 0))
diff --git a/ports/esp8266/modules/port_diag.py b/ports/esp8266/modules/port_diag.py
index ef88003..f2c69ec 100644
--- a/ports/esp8266/modules/port_diag.py
+++ b/ports/esp8266/modules/port_diag.py
@@ -10,13 +10,16 @@
     fid = esp.flash_id()
 
     print("FlashROM:")
-    print("Flash ID: %x (Vendor: %x Device: %x)" % (fid, fid & 0xff, fid & 0xff00 | fid >> 16))
+    print("Flash ID: %x (Vendor: %x Device: %x)" % (fid, fid & 0xFF, fid & 0xFF00 | fid >> 16))
 
     print("Flash bootloader data:")
     SZ_MAP = {0: "512KB", 1: "256KB", 2: "1MB", 3: "2MB", 4: "4MB"}
-    FREQ_MAP = {0: "40MHZ", 1: "26MHZ", 2: "20MHz", 0xf: "80MHz"}
+    FREQ_MAP = {0: "40MHZ", 1: "26MHZ", 2: "20MHz", 0xF: "80MHz"}
     print("Byte @2: %02x" % ROM[2])
-    print("Byte @3: %02x (Flash size: %s Flash freq: %s)" % (ROM[3], SZ_MAP.get(ROM[3] >> 4, "?"), FREQ_MAP.get(ROM[3] & 0xf)))
+    print(
+        "Byte @3: %02x (Flash size: %s Flash freq: %s)"
+        % (ROM[3], SZ_MAP.get(ROM[3] >> 4, "?"), FREQ_MAP.get(ROM[3] & 0xF))
+    )
     print("Firmware checksum:")
     print(esp.check_fw())
 
@@ -24,7 +27,9 @@
     print("STA ifconfig:", network.WLAN(network.STA_IF).ifconfig())
     print("AP ifconfig:", network.WLAN(network.AP_IF).ifconfig())
     print("Free WiFi driver buffers of type:")
-    for i, comm in enumerate(("1,2 TX", "4 Mngmt TX(len: 0x41-0x100)", "5 Mngmt TX (len: 0-0x40)", "7", "8 RX")):
+    for i, comm in enumerate(
+        ("1,2 TX", "4 Mngmt TX(len: 0x41-0x100)", "5 Mngmt TX (len: 0-0x40)", "7", "8 RX")
+    ):
         print("%d: %d (%s)" % (i, esp.esf_free_bufs(i), comm))
     print("lwIP PCBs:")
     lwip.print_pcbs()
diff --git a/ports/esp8266/moduos.c b/ports/esp8266/moduos.c
index b66d5cc..f04094f 100644
--- a/ports/esp8266/moduos.c
+++ b/ports/esp8266/moduos.c
@@ -135,5 +135,5 @@
 
 const mp_obj_module_t uos_module = {
     .base = { &mp_type_module },
-    .globals = (mp_obj_dict_t*)&os_module_globals,
+    .globals = (mp_obj_dict_t *)&os_module_globals,
 };
diff --git a/ports/esp8266/modutime.c b/ports/esp8266/modutime.c
index f531984..915f193 100644
--- a/ports/esp8266/modutime.c
+++ b/ports/esp8266/modutime.c
@@ -92,8 +92,8 @@
     }
 
     return mp_obj_new_int_from_uint(timeutils_mktime(mp_obj_get_int(elem[0]),
-            mp_obj_get_int(elem[1]), mp_obj_get_int(elem[2]), mp_obj_get_int(elem[3]),
-            mp_obj_get_int(elem[4]), mp_obj_get_int(elem[5])));
+        mp_obj_get_int(elem[1]), mp_obj_get_int(elem[2]), mp_obj_get_int(elem[3]),
+        mp_obj_get_int(elem[4]), mp_obj_get_int(elem[5])));
 }
 MP_DEFINE_CONST_FUN_OBJ_1(time_mktime_obj, time_mktime);
 
@@ -125,5 +125,5 @@
 
 const mp_obj_module_t utime_module = {
     .base = { &mp_type_module },
-    .globals = (mp_obj_dict_t*)&time_module_globals,
+    .globals = (mp_obj_dict_t *)&time_module_globals,
 };
diff --git a/ports/esp8266/mpconfigport.h b/ports/esp8266/mpconfigport.h
index ba4b1d0..71c49cd 100644
--- a/ports/esp8266/mpconfigport.h
+++ b/ports/esp8266/mpconfigport.h
@@ -110,13 +110,13 @@
         vm_hook_divisor = MICROPY_VM_HOOK_COUNT; \
         extern void ets_loop_iter(void); \
         ets_loop_iter(); \
-    }
+}
 #define MICROPY_VM_HOOK_LOOP MICROPY_VM_HOOK_POLL
 #define MICROPY_VM_HOOK_RETURN MICROPY_VM_HOOK_POLL
 
 // type definitions for the specific machine
 
-#define MICROPY_MAKE_POINTER_CALLABLE(p) ((void*)((mp_uint_t)(p)))
+#define MICROPY_MAKE_POINTER_CALLABLE(p) ((void *)((mp_uint_t)(p)))
 
 #define MP_SSIZE_MAX (0x7fffffff)
 
@@ -131,7 +131,7 @@
 #include <sys/types.h>
 
 #define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
-void *esp_native_code_commit(void*, size_t, void*);
+void *esp_native_code_commit(void *, size_t, void *);
 #define MP_PLAT_COMMIT_EXEC(buf, len, reloc) esp_native_code_commit(buf, len, reloc)
 
 // printer for debugging output, goes to UART only
diff --git a/ports/esp8266/strtoll.c b/ports/esp8266/strtoll.c
index 4e8a4d0..f095f76 100644
--- a/ports/esp8266/strtoll.c
+++ b/ports/esp8266/strtoll.c
@@ -23,7 +23,7 @@
         val = val * base + v;
     }
 
-    *endptr = (char*)nptr;
+    *endptr = (char *)nptr;
 
     return val;
 }
diff --git a/ports/esp8266/uart.c b/ports/esp8266/uart.c
index 61715f5..64bc78e 100644
--- a/ports/esp8266/uart.c
+++ b/ports/esp8266/uart.c
@@ -65,9 +65,9 @@
     uart_div_modify(uart_no, UART_CLK_FREQ / (UartDev.baut_rate));
 
     WRITE_PERI_REG(UART_CONF0(uart_no), UartDev.exist_parity
-                 | UartDev.parity
-                 | (UartDev.stop_bits << UART_STOP_BIT_NUM_S)
-                 | (UartDev.data_bits << UART_BIT_NUM_S));
+        | UartDev.parity
+        | (UartDev.stop_bits << UART_STOP_BIT_NUM_S)
+        | (UartDev.data_bits << UART_BIT_NUM_S));
 
     // clear rx and tx fifo,not ready
     SET_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST | UART_TXFIFO_RST);
@@ -76,16 +76,16 @@
     if (uart_no == UART0) {
         // set rx fifo trigger
         WRITE_PERI_REG(UART_CONF1(uart_no),
-                   ((0x10 & UART_RXFIFO_FULL_THRHD) << UART_RXFIFO_FULL_THRHD_S) |
-                   ((0x10 & UART_RX_FLOW_THRHD) << UART_RX_FLOW_THRHD_S) |
-                   UART_RX_FLOW_EN |
-                   (0x02 & UART_RX_TOUT_THRHD) << UART_RX_TOUT_THRHD_S |
-                   UART_RX_TOUT_EN);
+            ((0x10 & UART_RXFIFO_FULL_THRHD) << UART_RXFIFO_FULL_THRHD_S) |
+            ((0x10 & UART_RX_FLOW_THRHD) << UART_RX_FLOW_THRHD_S) |
+            UART_RX_FLOW_EN |
+            (0x02 & UART_RX_TOUT_THRHD) << UART_RX_TOUT_THRHD_S |
+                UART_RX_TOUT_EN);
         SET_PERI_REG_MASK(UART_INT_ENA(uart_no), UART_RXFIFO_TOUT_INT_ENA |
-                      UART_FRM_ERR_INT_ENA);
+            UART_FRM_ERR_INT_ENA);
     } else {
         WRITE_PERI_REG(UART_CONF1(uart_no),
-                   ((UartDev.rcv_buff.TrigLvl & UART_RXFIFO_FULL_THRHD) << UART_RXFIFO_FULL_THRHD_S));
+            ((UartDev.rcv_buff.TrigLvl & UART_RXFIFO_FULL_THRHD) << UART_RXFIFO_FULL_THRHD_S));
     }
 
     // clear all interrupt
@@ -103,7 +103,7 @@
 *******************************************************************************/
 void uart_tx_one_char(uint8 uart, uint8 TxChar) {
     while (true) {
-        uint32 fifo_cnt = READ_PERI_REG(UART_STATUS(uart)) & (UART_TXFIFO_CNT<<UART_TXFIFO_CNT_S);
+        uint32 fifo_cnt = READ_PERI_REG(UART_STATUS(uart)) & (UART_TXFIFO_CNT << UART_TXFIFO_CNT_S);
         if ((fifo_cnt >> UART_TXFIFO_CNT_S & UART_TXFIFO_CNT) < 126) {
             break;
         }
@@ -113,7 +113,7 @@
 
 void uart_flush(uint8 uart) {
     while (true) {
-        uint32 fifo_cnt = READ_PERI_REG(UART_STATUS(uart)) & (UART_TXFIFO_CNT<<UART_TXFIFO_CNT_S);
+        uint32 fifo_cnt = READ_PERI_REG(UART_STATUS(uart)) & (UART_TXFIFO_CNT << UART_TXFIFO_CNT_S);
         if ((fifo_cnt >> UART_TXFIFO_CNT_S & UART_TXFIFO_CNT) == 0) {
             break;
         }
@@ -155,9 +155,9 @@
 *******************************************************************************/
 
 static void uart0_rx_intr_handler(void *para) {
-  /* uart0 and uart1 intr combine togther, when interrupt occur, see reg 0x3ff20020, bit2, bit0 represents
-    * uart1 and uart0 respectively
-    */
+    /* uart0 and uart1 intr combine togther, when interrupt occur, see reg 0x3ff20020, bit2, bit0 represents
+      * uart1 and uart0 respectively
+      */
 
     uint8 uart_no = UART_REPL;
 
@@ -170,7 +170,7 @@
         // fifo full
         goto read_chars;
     } else if (UART_RXFIFO_TOUT_INT_ST == (READ_PERI_REG(UART_INT_ST(uart_no)) & UART_RXFIFO_TOUT_INT_ST)) {
-        read_chars:
+    read_chars:
         ETS_UART_INTR_DISABLE();
 
         while (READ_PERI_REG(UART_STATUS(uart_no)) & (UART_RXFIFO_CNT << UART_RXFIFO_CNT_S)) {
diff --git a/ports/esp8266/uart.h b/ports/esp8266/uart.h
index 0e67783..f187c31 100644
--- a/ports/esp8266/uart.h
+++ b/ports/esp8266/uart.h
@@ -58,17 +58,17 @@
 } RcvMsgBuffState;
 
 typedef struct {
-    uint32     RcvBuffSize;
-    uint8     *pRcvMsgBuff;
-    uint8     *pWritePos;
-    uint8     *pReadPos;
-    uint8      TrigLvl; //JLU: may need to pad
-    RcvMsgBuffState  BuffState;
+    uint32 RcvBuffSize;
+    uint8 *pRcvMsgBuff;
+    uint8 *pWritePos;
+    uint8 *pReadPos;
+    uint8 TrigLvl;      //JLU: may need to pad
+    RcvMsgBuffState BuffState;
 } RcvMsgBuff;
 
 typedef struct {
-    uint32   TrxBuffSize;
-    uint8   *pTrxBuff;
+    uint32 TrxBuffSize;
+    uint8 *pTrxBuff;
 } TrxMsgBuff;
 
 typedef enum {
@@ -80,17 +80,17 @@
 } RcvMsgState;
 
 typedef struct {
-    UartBautRate      baut_rate;
-    UartBitsNum4Char  data_bits;
-    UartExistParity   exist_parity;
-    UartParityMode    parity;    // chip size in byte
-    UartStopBitsNum   stop_bits;
-    UartFlowCtrl      flow_ctrl;
-    RcvMsgBuff        rcv_buff;
-    TrxMsgBuff        trx_buff;
-    RcvMsgState       rcv_state;
-    int               received;
-    int               buff_uart_no;  //indicate which uart use tx/rx buffer
+    UartBautRate baut_rate;
+    UartBitsNum4Char data_bits;
+    UartExistParity exist_parity;
+    UartParityMode parity;       // chip size in byte
+    UartStopBitsNum stop_bits;
+    UartFlowCtrl flow_ctrl;
+    RcvMsgBuff rcv_buff;
+    TrxMsgBuff trx_buff;
+    RcvMsgState rcv_state;
+    int received;
+    int buff_uart_no;                //indicate which uart use tx/rx buffer
 } UartDevice;
 
 extern uint8 uart_ringbuf_array[UART0_STATIC_RXBUF_LEN];
diff --git a/ports/esp8266/uart_register.h b/ports/esp8266/uart_register.h
index 6398879..cdf0ba1 100644
--- a/ports/esp8266/uart_register.h
+++ b/ports/esp8266/uart_register.h
@@ -6,7 +6,7 @@
 
 #ifndef UART_REGISTER_H_INCLUDED
 #define UART_REGISTER_H_INCLUDED
-#define REG_UART_BASE( i )  (0x60000000+(i)*0xf00)
+#define REG_UART_BASE( i )  (0x60000000 + (i) * 0xf00)
 //version value:32'h062000
 
 #define UART_FIFO( i )                          (REG_UART_BASE( i ) + 0x0)
diff --git a/ports/esp8266/xtirq.h b/ports/esp8266/xtirq.h
index 595052f..835f06b 100644
--- a/ports/esp8266/xtirq.h
+++ b/ports/esp8266/xtirq.h
@@ -31,7 +31,7 @@
 // returns the value of "intlevel" from the PS register
 static inline uint32_t query_irq(void) {
     uint32_t ps;
-    __asm__ volatile("rsr %0, ps" : "=a" (ps));
+    __asm__ volatile ("rsr %0, ps" : "=a" (ps));
     return ps & 0xf;
 }
 
@@ -45,7 +45,7 @@
 
 // "ps" should be the value returned from raise_irq_pri
 static inline void restore_irq_pri(uint32_t ps) {
-    __asm__ volatile ("wsr %0, ps; rsync" :: "a" (ps));
+    __asm__ volatile ("wsr %0, ps; rsync" : : "a" (ps));
 }
 
 static inline uint32_t disable_irq(void) {