nRF52 update with internal file system support
parent
36ec29d4e8
commit
60a23f0fb6
@ -0,0 +1 @@
|
||||
Subproject commit 07b43832ee53a4a248c30f5a3014e2632d8aeb88
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017 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.
|
||||
*/
|
||||
|
||||
// This file defines board specific functions.
|
||||
|
||||
#ifndef MICROPY_INCLUDED_NRF_BOARDS_BOARD_H
|
||||
#define MICROPY_INCLUDED_NRF_BOARDS_BOARD_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
extern volatile uint32_t ticks_ms;
|
||||
|
||||
// Initializes board related state once on start up.
|
||||
void board_init(void);
|
||||
|
||||
// Returns true if the user initiates safe mode in a board specific way.
|
||||
// Also add BOARD_USER_SAFE_MODE in mpconfigboard.h to explain the board specific
|
||||
// way.
|
||||
bool board_requests_safe_mode(void);
|
||||
|
||||
// Reset the state of off MCU components such as neopixels.
|
||||
void reset_board(void);
|
||||
|
||||
#endif // MICROPY_INCLUDED_NRF_BOARDS_BOARD_H
|
@ -0,0 +1,122 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017 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 <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "nrf.h"
|
||||
|
||||
#include "boards/board.h"
|
||||
|
||||
#if 0
|
||||
#include "common-hal/microcontroller/Pin.h"
|
||||
#include "hal/include/hal_gpio.h"
|
||||
#include "shared-bindings/digitalio/DigitalInOut.h"
|
||||
#include "shared-bindings/neopixel_write/__init__.h"
|
||||
#endif
|
||||
|
||||
// Must match temp register in bootloader
|
||||
#define BOOTLOADER_VERSION_REGISTER NRF_TIMER2->CC[0]
|
||||
uint32_t bootloaderVersion = 0;
|
||||
|
||||
volatile uint32_t ticks_ms = 0;
|
||||
|
||||
#define HAL_LFCLK_FREQ (32768UL)
|
||||
#define HAL_RTC_FREQ (1024UL)
|
||||
#define HAL_RTC_COUNTER_PRESCALER ((HAL_LFCLK_FREQ/HAL_RTC_FREQ)-1)
|
||||
|
||||
/* Maximum RTC ticks */
|
||||
#define portNRF_RTC_MAXTICKS ((1U<<24)-1U)
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
// Retrieve bootloader version
|
||||
bootloaderVersion = BOOTLOADER_VERSION_REGISTER;
|
||||
|
||||
// 32Khz XTAL
|
||||
NRF_CLOCK->LFCLKSRC = (uint32_t)((CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos) & CLOCK_LFCLKSRC_SRC_Msk);
|
||||
NRF_CLOCK->TASKS_LFCLKSTART = 1UL;
|
||||
|
||||
// Set up RTC1 as tick timer
|
||||
NVIC_DisableIRQ(RTC1_IRQn);
|
||||
NRF_RTC1->EVTENCLR = RTC_EVTEN_COMPARE0_Msk;
|
||||
NRF_RTC1->INTENCLR = RTC_INTENSET_COMPARE0_Msk;
|
||||
NRF_RTC1->TASKS_STOP = 1;
|
||||
NRF_RTC1->TASKS_CLEAR = 1;
|
||||
|
||||
ticks_ms = 0;
|
||||
|
||||
NRF_RTC1->PRESCALER = HAL_RTC_COUNTER_PRESCALER;
|
||||
NRF_RTC1->INTENSET = RTC_INTENSET_TICK_Msk;
|
||||
NRF_RTC1->TASKS_START = 1;
|
||||
NRF_RTC1->EVTENSET = RTC_EVTEN_OVRFLW_Msk;
|
||||
NVIC_SetPriority(RTC1_IRQn, 0xf); // lowest priority
|
||||
NVIC_EnableIRQ(RTC1_IRQn);
|
||||
}
|
||||
|
||||
void RTC1_IRQHandler(void)
|
||||
{
|
||||
// Clear event
|
||||
NRF_RTC1->EVENTS_TICK = 0;
|
||||
volatile uint32_t dummy = NRF_RTC1->EVENTS_TICK;
|
||||
(void) dummy;
|
||||
|
||||
// Tick correction
|
||||
uint32_t systick_counter = NRF_RTC1->COUNTER;
|
||||
uint32_t diff = (systick_counter - ticks_ms) & portNRF_RTC_MAXTICKS;
|
||||
ticks_ms += diff;
|
||||
}
|
||||
|
||||
// Check the status of the two buttons on CircuitPlayground Express. If both are
|
||||
// pressed, then boot into user safe mode.
|
||||
bool board_requests_safe_mode(void) {
|
||||
// gpio_set_pin_function(PIN_PA14, GPIO_PIN_FUNCTION_OFF);
|
||||
// gpio_set_pin_direction(PIN_PA14, GPIO_DIRECTION_IN);
|
||||
// gpio_set_pin_pull_mode(PIN_PA14, GPIO_PULL_DOWN);
|
||||
//
|
||||
// gpio_set_pin_function(PIN_PA28, GPIO_PIN_FUNCTION_OFF);
|
||||
// gpio_set_pin_direction(PIN_PA28, GPIO_DIRECTION_IN);
|
||||
// gpio_set_pin_pull_mode(PIN_PA28, GPIO_PULL_DOWN);
|
||||
// bool safe_mode = gpio_get_pin_level(PIN_PA14) &&
|
||||
// gpio_get_pin_level(PIN_PA28);
|
||||
// reset_pin(PIN_PA14);
|
||||
// reset_pin(PIN_PA28);
|
||||
// return safe_mode;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void reset_board(void) {
|
||||
// uint8_t empty[30];
|
||||
// memset(empty, 0, 30);
|
||||
// digitalio_digitalinout_obj_t neopixel_pin;
|
||||
// common_hal_digitalio_digitalinout_construct(&neopixel_pin, &pin_PB23);
|
||||
// common_hal_digitalio_digitalinout_switch_to_output(&neopixel_pin, false,
|
||||
// DRIVE_MODE_PUSH_PULL);
|
||||
// common_hal_neopixel_write(&neopixel_pin, empty, 30);
|
||||
// common_hal_digitalio_digitalinout_deinit(&neopixel_pin);
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
# Adafruit nRF52 Feather Single-Bank Bootloader
|
||||
|
||||
These files contain an implementation of a single-bank bootloader,
|
||||
which doubles the amount of flash memory available to applications
|
||||
at the expense of safe over the air updates.
|
||||
|
||||
Two versions are present, based on release **2.0.1** and **5.0.0**
|
||||
of the Nordic S132 SoftDevice. The SoftDevice is included as poart
|
||||
of the bootloader binary.
|
@ -0,0 +1,12 @@
|
||||
import board
|
||||
import digitalio
|
||||
import time
|
||||
|
||||
led = digitalio.DigitalInOut(board.LED2)
|
||||
led.direction = digitalio.Direction.OUTPUT
|
||||
|
||||
while True:
|
||||
led.value = True
|
||||
time.sleep(0.5)
|
||||
led.value = False
|
||||
time.sleep(0.5)
|
@ -0,0 +1,20 @@
|
||||
import board
|
||||
import busio
|
||||
|
||||
i2c = busio.I2C(board.SCL, board.SDA)
|
||||
count = 0
|
||||
|
||||
# Wait for I2C lock
|
||||
while not i2c.try_lock():
|
||||
pass
|
||||
|
||||
# Scan for devices on the I2C bus
|
||||
print("Scanning I2C bus")
|
||||
for x in i2c.scan():
|
||||
print(hex(x))
|
||||
count += 1
|
||||
|
||||
print("%d device(s) found on I2C bus" % count)
|
||||
|
||||
# Release the I2C bus
|
||||
i2c.unlock()
|
@ -0,0 +1,25 @@
|
||||
import time
|
||||
from board import *
|
||||
from pulseio import *
|
||||
|
||||
# Setup BLUE and RED LEDs as PWM output (default frequency is 500 Hz)
|
||||
ledb = PWMOut(LED2)
|
||||
ledr = PWMOut(LED1)
|
||||
|
||||
# Set the BLUE LED to have a duty cycle of 5000 (out of 65535, so ~7.5%)
|
||||
ledb.duty_cycle = 5000
|
||||
|
||||
# Setup pin A0 as a standard PWM out @ 50% to test on the oscilloscope.
|
||||
# You should see a 50% duty cycle waveform at ~500Hz on the scope when you
|
||||
# connect a probe to pin A0
|
||||
a0 = PWMOut(A0)
|
||||
a0.duty_cycle = int(65535/2)
|
||||
|
||||
# Constantly pulse the RED LED
|
||||
while True:
|
||||
for i in range(100):
|
||||
ledr.duty_cycle = int(i / 100 * 65535)
|
||||
time.sleep(0.01)
|
||||
for i in range(100, -1, -1):
|
||||
ledr.duty_cycle = int(i / 100 * 65535)
|
||||
time.sleep(0.01)
|
@ -0,0 +1,124 @@
|
||||
// This file was automatically generated by make-pins.py
|
||||
//
|
||||
// --af nrf52_af.csv
|
||||
// --board boards/feather52/pins.csv
|
||||
// --prefix boards/nrf52_prefix.c
|
||||
|
||||
// nrf52_prefix.c becomes the initial portion of the generated pins file.
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "py/mphal.h"
|
||||
#include "pin.h"
|
||||
|
||||
#define AF(af_idx, af_fn, af_unit, af_type, af_ptr) \
|
||||
{ \
|
||||
{ &pin_af_type }, \
|
||||
.name = MP_QSTR_AF ## af_idx ## _ ## af_fn ## af_unit, \
|
||||
.idx = (af_idx), \
|
||||
.fn = AF_FN_ ## af_fn, \
|
||||
.unit = (af_unit), \
|
||||
.type = AF_PIN_TYPE_ ## af_fn ## _ ## af_type, \
|
||||
.af_fn = (af_ptr) \
|
||||
}
|
||||
|
||||
#define PIN(p_port, p_pin, p_af, p_adc_channel) \
|
||||
{ \
|
||||
{ &mcu_pin_type }, \
|
||||
.name = MP_QSTR_ ## p_port ## p_pin, \
|
||||
.port = PORT_ ## p_port, \
|
||||
.pin = (p_pin), \
|
||||
.num_af = (sizeof(p_af) / sizeof(pin_af_obj_t)), \
|
||||
/*.pin_mask = (1 << p_pin), */\
|
||||
.af = p_af, \
|
||||
.adc_channel = p_adc_channel,\
|
||||
}
|
||||
|
||||
#define NO_ADC 0
|
||||
|
||||
const pin_obj_t pin_PA02 = PIN(A, 2, NULL, SAADC_CH_PSELP_PSELP_AnalogInput0);
|
||||
const pin_obj_t pin_PA03 = PIN(A, 3, NULL, SAADC_CH_PSELP_PSELP_AnalogInput1);
|
||||
const pin_obj_t pin_PA04 = PIN(A, 4, NULL, SAADC_CH_PSELP_PSELP_AnalogInput2);
|
||||
const pin_obj_t pin_PA05 = PIN(A, 5, NULL, SAADC_CH_PSELP_PSELP_AnalogInput3);
|
||||
const pin_obj_t pin_PA06 = PIN(A, 6, NULL, NO_ADC);
|
||||
const pin_obj_t pin_PA07 = PIN(A, 7, NULL, NO_ADC);
|
||||
const pin_obj_t pin_PA08 = PIN(A, 8, NULL, NO_ADC);
|
||||
const pin_obj_t pin_PA09 = PIN(A, 9, NULL, NO_ADC);
|
||||
const pin_obj_t pin_PA10 = PIN(A, 10, NULL, NO_ADC);
|
||||
const pin_obj_t pin_PA11 = PIN(A, 11, NULL, NO_ADC);
|
||||
const pin_obj_t pin_PA12 = PIN(A, 12, NULL, NO_ADC);
|
||||
const pin_obj_t pin_PA13 = PIN(A, 13, NULL, NO_ADC);
|
||||
const pin_obj_t pin_PA14 = PIN(A, 14, NULL, NO_ADC);
|
||||
const pin_obj_t pin_PA15 = PIN(A, 15, NULL, NO_ADC);
|
||||
const pin_obj_t pin_PA16 = PIN(A, 16, NULL, NO_ADC);
|
||||
const pin_obj_t pin_PA17 = PIN(A, 17, NULL, NO_ADC);
|
||||
|
||||
const pin_obj_t pin_PA19 = PIN(A, 19, NULL, NO_ADC);
|
||||
const pin_obj_t pin_PA20 = PIN(A, 20, NULL, NO_ADC);
|
||||
|
||||
const pin_obj_t pin_PA25 = PIN(A, 25, NULL, NO_ADC);
|
||||
const pin_obj_t pin_PA26 = PIN(A, 26, NULL, NO_ADC);
|
||||
const pin_obj_t pin_PA27 = PIN(A, 27, NULL, NO_ADC);
|
||||
const pin_obj_t pin_PA28 = PIN(A, 28, NULL, SAADC_CH_PSELP_PSELP_AnalogInput4);
|
||||
const pin_obj_t pin_PA29 = PIN(A, 29, NULL, SAADC_CH_PSELP_PSELP_AnalogInput5);
|
||||
const pin_obj_t pin_PA30 = PIN(A, 30, NULL, SAADC_CH_PSELP_PSELP_AnalogInput6);
|
||||
const pin_obj_t pin_PA31 = PIN(A, 31, NULL, SAADC_CH_PSELP_PSELP_AnalogInput7);
|
||||
|
||||
STATIC const mp_rom_map_elem_t mcu_pin_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA02), MP_ROM_PTR(&pin_PA02) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA03), MP_ROM_PTR(&pin_PA03) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA04), MP_ROM_PTR(&pin_PA04) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA05), MP_ROM_PTR(&pin_PA05) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA06), MP_ROM_PTR(&pin_PA06) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA07), MP_ROM_PTR(&pin_PA07) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA08), MP_ROM_PTR(&pin_PA08) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA09), MP_ROM_PTR(&pin_PA09) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA10), MP_ROM_PTR(&pin_PA10) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA11), MP_ROM_PTR(&pin_PA11) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA12), MP_ROM_PTR(&pin_PA12) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA13), MP_ROM_PTR(&pin_PA13) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA14), MP_ROM_PTR(&pin_PA14) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA15), MP_ROM_PTR(&pin_PA15) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA16), MP_ROM_PTR(&pin_PA16) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA17), MP_ROM_PTR(&pin_PA17) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA19), MP_ROM_PTR(&pin_PA19) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA20), MP_ROM_PTR(&pin_PA20) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA25), MP_ROM_PTR(&pin_PA25) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA26), MP_ROM_PTR(&pin_PA26) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA27), MP_ROM_PTR(&pin_PA27) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA28), MP_ROM_PTR(&pin_PA28) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA29), MP_ROM_PTR(&pin_PA29) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA30), MP_ROM_PTR(&pin_PA30) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA31), MP_ROM_PTR(&pin_PA31) },
|
||||
};
|
||||
MP_DEFINE_CONST_DICT(mcu_pin_globals, mcu_pin_globals_table);
|
||||
|
||||
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_A0 ), MP_ROM_PTR(&pin_PA02) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_A1 ), MP_ROM_PTR(&pin_PA03) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_A2 ), MP_ROM_PTR(&pin_PA04) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_A3 ), MP_ROM_PTR(&pin_PA05) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_TX ), MP_ROM_PTR(&pin_PA06) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_A7 ), MP_ROM_PTR(&pin_PA07) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_RX ), MP_ROM_PTR(&pin_PA08) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_NFC1 ), MP_ROM_PTR(&pin_PA09) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_NFC2 ), MP_ROM_PTR(&pin_PA10) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D11 ), MP_ROM_PTR(&pin_PA11) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_SCK ), MP_ROM_PTR(&pin_PA12) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_MOSI ), MP_ROM_PTR(&pin_PA13) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_MISO ), MP_ROM_PTR(&pin_PA14) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D15 ), MP_ROM_PTR(&pin_PA15) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D16 ), MP_ROM_PTR(&pin_PA16) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_LED1 ), MP_ROM_PTR(&pin_PA17) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_LED2 ), MP_ROM_PTR(&pin_PA19) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_DFU ), MP_ROM_PTR(&pin_PA20) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_SDA ), MP_ROM_PTR(&pin_PA25) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_SCL ), MP_ROM_PTR(&pin_PA26) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D27 ), MP_ROM_PTR(&pin_PA27) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_A4 ), MP_ROM_PTR(&pin_PA28) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_A5 ), MP_ROM_PTR(&pin_PA29) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_A6 ), MP_ROM_PTR(&pin_PA30) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_A7 ), MP_ROM_PTR(&pin_PA31) },
|
||||
};
|
||||
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
|
@ -1,25 +1,25 @@
|
||||
PA2,PA2,ADC0_IN0
|
||||
PA3,PA3,ADC0_IN1
|
||||
PA4,PA4,ADC0_IN2
|
||||
PA5,PA5,ADC0_IN3
|
||||
UART_TX,PA6
|
||||
A0,PA2,ADC0_IN0
|
||||
A1,PA3,ADC0_IN1
|
||||
A2,PA4,ADC0_IN2
|
||||
A3,PA5,ADC0_IN3
|
||||
TX,PA6
|
||||
PA7,PA7
|
||||
UART_RX,PA8
|
||||
RX,PA8
|
||||
NFC1,PA9
|
||||
NFC2,PA10
|
||||
PA11,PA11
|
||||
SPI_SCK,PA12
|
||||
SPI_MOSI,PA13
|
||||
SPI_MISO,PA14
|
||||
PA15,PA15
|
||||
PA16,PA16
|
||||
D11,PA11
|
||||
SCK,PA12
|
||||
MOSI,PA13
|
||||
MISO,PA14
|
||||
D15,PA15
|
||||
D16,PA16
|
||||
LED1,PA17
|
||||
LED2,PA19
|
||||
PA20,PA20
|
||||
I2C_SDA,PA25
|
||||
I2C_SCL,PA26
|
||||
PA27,PA27
|
||||
PA28,PA28,ADC0_IN4
|
||||
PA29,PA29,ADC0_IN5
|
||||
PA30,PA30,ADC0_IN6
|
||||
PA31,PA31,ADC0_IN7
|
||||
DFU,PA20
|
||||
SDA,PA25
|
||||
SCL,PA26
|
||||
D27,PA27
|
||||
A4,PA28,ADC0_IN4
|
||||
A5,PA29,ADC0_IN5
|
||||
A6,PA30,ADC0_IN6
|
||||
A7,PA31,ADC0_IN7
|
||||
|
|
@ -0,0 +1,28 @@
|
||||
extern const pin_obj_t pin_PA02;
|
||||
extern const pin_obj_t pin_PA03;
|
||||
extern const pin_obj_t pin_PA04;
|
||||
extern const pin_obj_t pin_PA05;
|
||||
extern const pin_obj_t pin_PA06;
|
||||
extern const pin_obj_t pin_PA07;
|
||||
extern const pin_obj_t pin_PA08;
|
||||
extern const pin_obj_t pin_PA09;
|
||||
extern const pin_obj_t pin_PA10;
|
||||
extern const pin_obj_t pin_PA11;
|
||||
extern const pin_obj_t pin_PA12;
|
||||
extern const pin_obj_t pin_PA13;
|
||||
extern const pin_obj_t pin_PA14;
|
||||
extern const pin_obj_t pin_PA15;
|
||||
extern const pin_obj_t pin_PA16;
|
||||
extern const pin_obj_t pin_PA17;
|
||||
extern const pin_obj_t pin_PA19;
|
||||
extern const pin_obj_t pin_PA20;
|
||||
extern const pin_obj_t pin_PA25;
|
||||
extern const pin_obj_t pin_PA26;
|
||||
extern const pin_obj_t pin_PA27;
|
||||
extern const pin_obj_t pin_PA28;
|
||||
extern const pin_obj_t pin_PA29;
|
||||
extern const pin_obj_t pin_PA30;
|
||||
extern const pin_obj_t pin_PA31;
|
||||
extern const pin_obj_t * const pin_PAdc1[];
|
||||
extern const pin_obj_t * const pin_PAdc2[];
|
||||
extern const pin_obj_t * const pin_PAdc3[];
|
@ -0,0 +1,118 @@
|
||||
/*
|
||||
* 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 "common-hal/analogio/AnalogIn.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "py/gc.h"
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/binary.h"
|
||||
#include "py/mphal.h"
|
||||
#include "shared-bindings/analogio/AnalogIn.h"
|
||||
#include "nrf.h"
|
||||
|
||||
void common_hal_analogio_analogin_construct(analogio_analogin_obj_t* self, const mcu_pin_obj_t *pin) {
|
||||
if (!pin->adc_channel) {
|
||||
// No ADC function on that pin
|
||||
mp_raise_ValueError("Pin does not have ADC capabilities");
|
||||
}
|
||||
|
||||
hal_gpio_cfg_pin(pin->port, pin->pin, HAL_GPIO_MODE_INPUT, HAL_GPIO_PULL_DISABLED);
|
||||
self->pin = pin;
|
||||
}
|
||||
|
||||
bool common_hal_analogio_analogin_deinited(analogio_analogin_obj_t *self) {
|
||||
return self->pin == mp_const_none;
|
||||
}
|
||||
|
||||
void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) {
|
||||
if (common_hal_analogio_analogin_deinited(self)) {
|
||||
return;
|
||||
}
|
||||
reset_pin(self->pin->pin);
|
||||
self->pin = mp_const_none;
|
||||
}
|
||||
|
||||
void analogin_reset() {
|
||||
}
|
||||
|
||||
uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
|
||||
// Something else might have used the ADC in a different way,
|
||||
// so we completely re-initialize it.
|
||||
|
||||
int16_t value;
|
||||
|
||||
NRF_SAADC->RESOLUTION = SAADC_RESOLUTION_VAL_14bit;
|
||||
NRF_SAADC->ENABLE = 1;
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
NRF_SAADC->CH[i].PSELN = SAADC_CH_PSELP_PSELP_NC;
|
||||
NRF_SAADC->CH[i].PSELP = SAADC_CH_PSELP_PSELP_NC;
|
||||
}
|
||||
|
||||
NRF_SAADC->CH[0].CONFIG = ((SAADC_CH_CONFIG_RESP_Bypass << SAADC_CH_CONFIG_RESP_Pos) & SAADC_CH_CONFIG_RESP_Msk)
|
||||
| ((SAADC_CH_CONFIG_RESP_Bypass << SAADC_CH_CONFIG_RESN_Pos) & SAADC_CH_CONFIG_RESN_Msk)
|
||||
| ((SAADC_CH_CONFIG_GAIN_Gain1_6 << SAADC_CH_CONFIG_GAIN_Pos) & SAADC_CH_CONFIG_GAIN_Msk)
|
||||
| ((SAADC_CH_CONFIG_REFSEL_Internal << SAADC_CH_CONFIG_REFSEL_Pos) & SAADC_CH_CONFIG_REFSEL_Msk)
|
||||
| ((SAADC_CH_CONFIG_TACQ_3us << SAADC_CH_CONFIG_TACQ_Pos) & SAADC_CH_CONFIG_TACQ_Msk)
|
||||
| ((SAADC_CH_CONFIG_MODE_SE << SAADC_CH_CONFIG_MODE_Pos) & SAADC_CH_CONFIG_MODE_Msk);
|
||||
NRF_SAADC->CH[0].PSELN = self->pin->adc_channel;
|
||||
NRF_SAADC->CH[0].PSELP = self->pin->adc_channel;
|
||||
|
||||
|
||||
NRF_SAADC->RESULT.PTR = (uint32_t)&value;
|
||||
NRF_SAADC->RESULT.MAXCNT = 1;
|
||||
|
||||
NRF_SAADC->TASKS_START = 0x01UL;
|
||||
|
||||
while (!NRF_SAADC->EVENTS_STARTED);
|
||||
NRF_SAADC->EVENTS_STARTED = 0x00UL;
|
||||
|
||||
NRF_SAADC->TASKS_SAMPLE = 0x01UL;
|
||||
|
||||
while (!NRF_SAADC->EVENTS_END);
|
||||
NRF_SAADC->EVENTS_END = 0x00UL;
|
||||
|
||||
NRF_SAADC->TASKS_STOP = 0x01UL;
|
||||
|
||||
while (!NRF_SAADC->EVENTS_STOPPED);
|
||||
NRF_SAADC->EVENTS_STOPPED = 0x00UL;
|
||||
|
||||
if (value < 0) {
|
||||
value = 0;
|
||||
}
|
||||
|
||||
NRF_SAADC->ENABLE = 0;
|
||||
|
||||
// Map value to from 14 to 16 bits
|
||||
return (value << 2);
|
||||
}
|
||||
|
||||
float common_hal_analogio_analogin_get_reference_voltage(analogio_analogin_obj_t *self) {
|
||||
return 3.3f;
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 Scott Shawcroft
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_ANALOGIO_ANALOGIN_H
|
||||
#define MICROPY_INCLUDED_NRF_COMMON_HAL_ANALOGIO_ANALOGIN_H
|
||||
|
||||
#include "common-hal/microcontroller/Pin.h"
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
const mcu_pin_obj_t * pin;
|
||||
} analogio_analogin_obj_t;
|
||||
|
||||
void analogin_reset(void);
|
||||
|
||||
#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_ANALOGIO_ANALOGIN_H
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2013, 2014 Damien P. George
|
||||
*
|
||||
* 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 <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "py/mperrno.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "shared-bindings/analogio/AnalogOut.h"
|
||||
|
||||
|
||||
void common_hal_analogio_analogout_construct(analogio_analogout_obj_t* self, const mcu_pin_obj_t *pin) {
|
||||
// if (pin->pin != PIN_PA02) {
|
||||
// mp_raise_ValueError("AnalogOut not supported on given pin");
|
||||
// return;
|
||||
// }
|
||||
// struct dac_config config_dac;
|
||||
// dac_get_config_defaults(&config_dac);
|
||||
// config_dac.reference = DAC_REFERENCE_AVCC;
|
||||
// enum status_code status = dac_init(&self->dac_instance, DAC, &config_dac);
|
||||
// if (status != STATUS_OK) {
|
||||
// mp_raise_OSError(MP_EIO);
|
||||
// return;
|
||||
// }
|
||||
// claim_pin(pin);
|
||||
//
|
||||
// struct dac_chan_config config_analogout_chan;
|
||||
// dac_chan_get_config_defaults(&config_analogout_chan);
|
||||
// dac_chan_set_config(&self->dac_instance, DAC_CHANNEL_0, &config_analogout_chan);
|
||||
// dac_chan_enable(&self->dac_instance, DAC_CHANNEL_0);
|
||||
//
|
||||
// dac_enable(&self->dac_instance);
|
||||
}
|
||||
|
||||
bool common_hal_analogio_analogout_deinited(analogio_analogout_obj_t *self) {
|
||||
return self->deinited;
|
||||
}
|
||||
|
||||
void common_hal_analogio_analogout_deinit(analogio_analogout_obj_t *self) {
|
||||
// if (common_hal_analogio_analogout_deinited(self)) {
|
||||
// return;
|
||||
// }
|
||||
// dac_disable(&self->dac_instance);
|
||||
// dac_chan_disable(&self->dac_instance, DAC_CHANNEL_0);
|
||||
// reset_pin(PIN_PA02);
|
||||
// self->deinited = true;
|
||||
}
|
||||
|
||||
void common_hal_analogio_analogout_set_value(analogio_analogout_obj_t *self, uint16_t value) {
|
||||
// Input is 16 bit but we only support 10 bit so we shift the input.
|
||||
// dac_chan_write(&self->dac_instance, DAC_CHANNEL_0, value >> 6);
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 Scott Shawcroft
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_ANALOGIO_ANALOGOUT_H
|
||||
#define MICROPY_INCLUDED_NRF_COMMON_HAL_ANALOGIO_ANALOGOUT_H
|
||||
|
||||
#include "common-hal/microcontroller/Pin.h"
|
||||
|
||||
//#include "asf/sam0/drivers/dac/dac.h"
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
// struct dac_module dac_instance;
|
||||
bool deinited;
|
||||
} analogio_analogout_obj_t;
|
||||
|
||||
#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_ANALOGIO_ANALOGOUT_H
|
@ -0,0 +1 @@
|
||||
// No analogio module functions.
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2013, 2014 Damien P. George
|
||||
*
|
||||
* 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 <string.h>
|
||||
|
||||
#include "py/runtime.h"
|
||||
#include "py/mphal.h"
|
||||
#include "common-hal/microcontroller/Pin.h"
|
||||
|
||||
// Pins aren't actually defined here. They are in the board specific directory
|
||||
// such as boards/arduino_zero/pins.c.
|
@ -0,0 +1,207 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 Sandeep Mistry All right reserved.
|
||||
* Copyright (c) 2017 hathach
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||