2016-11-03 18:50:59 -04:00
|
|
|
/*
|
|
|
|
* This file is part of the MicroPython project, http://micropython.org/
|
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2016 Scott Shawcroft for Adafruit Industries
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "py/mphal.h"
|
2017-08-25 16:00:27 -04:00
|
|
|
#include "py/obj.h"
|
2017-09-22 21:05:51 -04:00
|
|
|
#include "hal/include/hal_atomic.h"
|
2016-11-03 18:50:59 -04:00
|
|
|
|
|
|
|
#include "samd21_pins.h"
|
|
|
|
|
2017-08-25 16:00:27 -04:00
|
|
|
#include "shared-bindings/nvm/ByteArray.h"
|
2017-08-31 13:48:30 -04:00
|
|
|
#include "shared-bindings/microcontroller/Processor.h"
|
2017-08-25 16:00:27 -04:00
|
|
|
|
2016-11-03 18:50:59 -04:00
|
|
|
void common_hal_mcu_delay_us(uint32_t delay) {
|
|
|
|
mp_hal_delay_us(delay);
|
|
|
|
}
|
|
|
|
|
2016-11-30 18:08:34 -05:00
|
|
|
// Interrupt flags that will be saved and restored during disable/Enable
|
|
|
|
// interrupt functions below.
|
2017-09-22 21:05:51 -04:00
|
|
|
volatile hal_atomic_t flags;
|
2016-11-30 18:08:34 -05:00
|
|
|
void common_hal_mcu_disable_interrupts(void) {
|
2017-09-22 21:05:51 -04:00
|
|
|
atomic_enter_critical(&flags);
|
2016-11-30 18:08:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void common_hal_mcu_enable_interrupts(void) {
|
2017-09-22 21:05:51 -04:00
|
|
|
atomic_leave_critical(&flags);
|
2016-11-30 18:08:34 -05:00
|
|
|
}
|
|
|
|
|
2017-08-31 13:48:30 -04:00
|
|
|
// The singleton microcontroller.Processor object, bound to microcontroller.cpu
|
|
|
|
// It currently only has properties, and no state.
|
|
|
|
mcu_processor_obj_t common_hal_mcu_processor_obj = {
|
|
|
|
.base = {
|
|
|
|
.type = &mcu_processor_type,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2017-08-25 16:00:27 -04:00
|
|
|
// NVM is only available on Express boards for now.
|
|
|
|
#if CIRCUITPY_INTERNAL_NVM_SIZE > 0
|
2017-08-31 13:48:30 -04:00
|
|
|
// The singleton nvm.ByteArray object.
|
2017-09-22 21:05:51 -04:00
|
|
|
// nvm_bytearray_obj_t common_hal_mcu_nvm_obj = {
|
|
|
|
// .base = {
|
|
|
|
// .type = &nvm_bytearray_type,
|
|
|
|
// },
|
|
|
|
// .len = NVMCTRL_ROW_SIZE,
|
|
|
|
// .start_address = (uint8_t*) (FLASH_SIZE - NVMCTRL_ROW_SIZE)
|
|
|
|
// };
|
2017-08-25 16:00:27 -04:00
|
|
|
#endif
|
|
|
|
|
2016-11-03 18:50:59 -04:00
|
|
|
// This maps MCU pin names to pin objects.
|
2017-08-27 15:02:50 -04:00
|
|
|
STATIC const mp_rom_map_elem_t mcu_pin_global_dict_table[] = {
|
2016-11-03 18:50:59 -04:00
|
|
|
// Pins in datasheet order.
|
|
|
|
#ifdef PIN_PA00
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PA00), MP_ROM_PTR(&pin_PA00) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PA01
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PA01), MP_ROM_PTR(&pin_PA01) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PA02
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PA02), MP_ROM_PTR(&pin_PA02) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PA03
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PA03), MP_ROM_PTR(&pin_PA03) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PB04
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PB04), MP_ROM_PTR(&pin_PB04) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PB05
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PB05), MP_ROM_PTR(&pin_PB05) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PB06
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PB06), MP_ROM_PTR(&pin_PB06) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PB07
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PB07), MP_ROM_PTR(&pin_PB07) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PB08
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PB08), MP_ROM_PTR(&pin_PB08) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PB09
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PB09), MP_ROM_PTR(&pin_PB09) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PA04
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PA04), MP_ROM_PTR(&pin_PA04) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PA05
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PA05), MP_ROM_PTR(&pin_PA05) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PA06
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PA06), MP_ROM_PTR(&pin_PA06) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PA07
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PA07), MP_ROM_PTR(&pin_PA07) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PA08
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PA08), MP_ROM_PTR(&pin_PA08) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PA09
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PA09), MP_ROM_PTR(&pin_PA09) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PA10
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PA10), MP_ROM_PTR(&pin_PA10) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PA11
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PA11), MP_ROM_PTR(&pin_PA11) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PB10
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PB10), MP_ROM_PTR(&pin_PB10) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PB11
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PB11), MP_ROM_PTR(&pin_PB11) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PB12
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PB12), MP_ROM_PTR(&pin_PB12) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PB13
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PB13), MP_ROM_PTR(&pin_PB13) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PB14
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PB14), MP_ROM_PTR(&pin_PB14) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Second page.
|
|
|
|
#ifdef PIN_PB15
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PB15), MP_ROM_PTR(&pin_PB15) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PA12
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PA12), MP_ROM_PTR(&pin_PA12) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PA13
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PA13), MP_ROM_PTR(&pin_PA13) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PA14
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PA14), MP_ROM_PTR(&pin_PA14) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PA15
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PA15), MP_ROM_PTR(&pin_PA15) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PA16
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PA16), MP_ROM_PTR(&pin_PA16) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PA17
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PA17), MP_ROM_PTR(&pin_PA17) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PA18
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PA18), MP_ROM_PTR(&pin_PA18) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PA19
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PA19), MP_ROM_PTR(&pin_PA19) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PB16
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PB16), MP_ROM_PTR(&pin_PB16) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PB17
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PB17), MP_ROM_PTR(&pin_PB17) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PA20
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PA20), MP_ROM_PTR(&pin_PA20) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PA21
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PA21), MP_ROM_PTR(&pin_PA21) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PA22
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PA22), MP_ROM_PTR(&pin_PA22) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PA23
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PA23), MP_ROM_PTR(&pin_PA23) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PA24
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PA24), MP_ROM_PTR(&pin_PA24) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PA25
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PA25), MP_ROM_PTR(&pin_PA25) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PB22
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PB22), MP_ROM_PTR(&pin_PB22) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PB23
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PB23), MP_ROM_PTR(&pin_PB23) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PA27
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PA27), MP_ROM_PTR(&pin_PA27) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PA28
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PA28), MP_ROM_PTR(&pin_PA28) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PA30
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PA30), MP_ROM_PTR(&pin_PA30) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PA31
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PA31), MP_ROM_PTR(&pin_PA31) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PB30
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PB30), MP_ROM_PTR(&pin_PB30) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PB31
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PB31), MP_ROM_PTR(&pin_PB31) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PB00
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PB00), MP_ROM_PTR(&pin_PB00) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PB01
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PB01), MP_ROM_PTR(&pin_PB01) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PB02
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PB02), MP_ROM_PTR(&pin_PB02) },
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
#ifdef PIN_PB03
|
2017-08-27 15:02:50 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_PB03), MP_ROM_PTR(&pin_PB03) }
|
2016-11-03 18:50:59 -04:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
MP_DEFINE_CONST_DICT(mcu_pin_globals, mcu_pin_global_dict_table);
|