mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #15955 from aabadie/pr/boards/microbit-v2
boards: add support for microbit v2
This commit is contained in:
commit
3e3c4d06fb
@ -2,7 +2,7 @@ ifneq (,$(filter saul_default,$(USEMODULE)))
|
||||
USEMODULE += saul_nrf_temperature
|
||||
endif
|
||||
|
||||
ifneq (,$(filter nrf52811xxaa nrf52820xxaa rf52833xxaa nrf52840xxaa,$(CPU_MODEL)))
|
||||
ifneq (,$(filter nrf52811xxaa nrf52820xxaa nrf52833xxaa nrf52840xxaa,$(CPU_MODEL)))
|
||||
# include dependencies for 802.15.4 radio
|
||||
include $(RIOTBOARD)/common/nrf52/Makefile.nrf802154.dep
|
||||
else
|
||||
|
46
boards/common/nrf52/include/cfg_clock_32_0.h
Normal file
46
boards/common/nrf52/include/cfg_clock_32_0.h
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Inria
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup boards_common_nrf52
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Common clock configuration for the nRF52 based boards
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CFG_CLOCK_32_0_H
|
||||
#define CFG_CLOCK_32_0_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @name Clock configuration
|
||||
*
|
||||
* @note The radio will not work with the internal RC oscillator!
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define CLOCK_HFCLK (32U) /* set to 0: internal RC oscillator
|
||||
* 32: 32MHz crystal */
|
||||
#define CLOCK_LFCLK (0) /* set to 0: internal RC oscillator
|
||||
* 1: 32.768 kHz crystal
|
||||
* 2: derived from HFCLK */
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CFG_CLOCK_32_0_H */
|
||||
/** @} */
|
20
boards/microbit-v2/Kconfig
Normal file
20
boards/microbit-v2/Kconfig
Normal file
@ -0,0 +1,20 @@
|
||||
# Copyright (c) 2021 Inria
|
||||
|
||||
# This file is subject to the terms and conditions of the GNU Lesser
|
||||
# General Public License v2.1. See the file LICENSE in the top level
|
||||
# directory for more details.
|
||||
|
||||
config BOARD
|
||||
default "microbit-v2" if BOARD_MICROBIT_V2
|
||||
|
||||
config BOARD_MICROBIT_V2
|
||||
bool
|
||||
default y
|
||||
select BOARD_COMMON_NRF52
|
||||
select CPU_MODEL_NRF52833XXAA
|
||||
select HAS_PERIPH_I2C
|
||||
select HAS_PERIPH_PWM
|
||||
select HAS_PERIPH_SPI
|
||||
select HAS_PERIPH_UART
|
||||
|
||||
source "$(RIOTBOARD)/common/nrf52/Kconfig"
|
7
boards/microbit-v2/Makefile
Normal file
7
boards/microbit-v2/Makefile
Normal file
@ -0,0 +1,7 @@
|
||||
MODULE = board
|
||||
|
||||
ifneq (,$(filter microbit,$(USEMODULE)))
|
||||
DIRS += microbit
|
||||
endif
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
10
boards/microbit-v2/Makefile.dep
Normal file
10
boards/microbit-v2/Makefile.dep
Normal file
@ -0,0 +1,10 @@
|
||||
ifneq (,$(filter microbit,$(USEMODULE)))
|
||||
USEMODULE += xtimer
|
||||
USEMODULE += mineplex
|
||||
endif
|
||||
|
||||
ifneq (,$(filter saul_default,$(USEMODULE)))
|
||||
USEMODULE += saul_gpio
|
||||
endif
|
||||
|
||||
include $(RIOTBOARD)/common/nrf52/Makefile.dep
|
10
boards/microbit-v2/Makefile.features
Normal file
10
boards/microbit-v2/Makefile.features
Normal file
@ -0,0 +1,10 @@
|
||||
CPU_MODEL = nrf52833xxaa
|
||||
|
||||
# Put defined MCU peripherals here (in alphabetical order)
|
||||
FEATURES_PROVIDED += periph_i2c
|
||||
FEATURES_PROVIDED += periph_pwm
|
||||
FEATURES_PROVIDED += periph_spi
|
||||
FEATURES_PROVIDED += periph_uart
|
||||
|
||||
# include common nrf52 based boards features
|
||||
include $(RIOTBOARD)/common/nrf52/Makefile.features
|
12
boards/microbit-v2/Makefile.include
Normal file
12
boards/microbit-v2/Makefile.include
Normal file
@ -0,0 +1,12 @@
|
||||
# for this board, flash with OpenOCD by default. PyOCD is also supported.
|
||||
PROGRAMMER ?= openocd
|
||||
ifeq (pyocd,$(PROGRAMMER))
|
||||
# The board is not recognized automatically by pyocd, so the CPU target
|
||||
# option is passed explicitly
|
||||
FLASH_TARGET_TYPE ?= -t $(CPU)
|
||||
else ifeq (openocd,$(PROGRAMMER))
|
||||
DEBUG_ADAPTER = dap
|
||||
endif
|
||||
|
||||
# include nrf52 boards common configuration
|
||||
include $(RIOTBOARD)/common/nrf52/Makefile.include
|
32
boards/microbit-v2/board.c
Normal file
32
boards/microbit-v2/board.c
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Inria
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup boards_microbit_v2
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Board initialization code for the BBC micro:bit v2
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "board.h"
|
||||
#include "periph/gpio.h"
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
/* initialize the CPU */
|
||||
cpu_init();
|
||||
|
||||
/* initialize the on board buttons */
|
||||
gpio_init(BTN0_PIN, GPIO_IN);
|
||||
gpio_init(BTN1_PIN, GPIO_IN);
|
||||
}
|
36
boards/microbit-v2/doc.txt
Normal file
36
boards/microbit-v2/doc.txt
Normal file
@ -0,0 +1,36 @@
|
||||
/**
|
||||
@defgroup boards_microbit_v2 BBC micro:bit v2
|
||||
@ingroup boards
|
||||
@brief Support for the BBC micro:bit v2
|
||||
|
||||
## Overview
|
||||
|
||||
The [micro:bit v2](https://www.microbit.co.uk/) was designed by the BBC and
|
||||
released in 2020.
|
||||
|
||||
The board is based on the Nordic nRF52833 SoC, featuring 128KiB of RAM, 512KiB
|
||||
of ROM, and a 2.4GHz radio, that supports Bluetooth Low Energy (BLE), 802.15.4
|
||||
as well as a Nordic proprietary radio mode.
|
||||
|
||||
Additionally the boards features 2 buttons, a 5x5 LED matrix, a speaker, a
|
||||
microphone, an accelerometer and a magnetometer.
|
||||
|
||||
## Flashing and Debugging
|
||||
|
||||
The board can be flashed using OpenOCD and PyOCD. Debugger is also available
|
||||
with both programmers.
|
||||
|
||||
```
|
||||
BOARD=microbit make flash
|
||||
```
|
||||
|
||||
## STDIO
|
||||
|
||||
The programmer chip provides access to STDIO via USB. On Linux, stdio is
|
||||
usually available on /dev/ttyACM0. Use the `term` target to access stdio:
|
||||
|
||||
```
|
||||
BOARD=microbit make term
|
||||
```
|
||||
|
||||
*/
|
82
boards/microbit-v2/include/board.h
Normal file
82
boards/microbit-v2/include/board.h
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Inria
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup boards_microbit_v2
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Board specific configuration for the BBC micro:bit v2
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
*/
|
||||
|
||||
#ifndef BOARD_H
|
||||
#define BOARD_H
|
||||
|
||||
#include "board_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @name LED matrix pin configuration
|
||||
* @{
|
||||
*/
|
||||
#define MICROBIT_LED_COL1 GPIO_PIN(0, 28)
|
||||
#define MICROBIT_LED_COL2 GPIO_PIN(0, 11)
|
||||
#define MICROBIT_LED_COL3 GPIO_PIN(0, 31)
|
||||
#define MICROBIT_LED_COL4 GPIO_PIN(1, 5)
|
||||
#define MICROBIT_LED_COL5 GPIO_PIN(0, 30)
|
||||
#define MICROBIT_LED_ROW1 GPIO_PIN(0, 21)
|
||||
#define MICROBIT_LED_ROW2 GPIO_PIN(0, 22)
|
||||
#define MICROBIT_LED_ROW3 GPIO_PIN(0, 15)
|
||||
#define MICROBIT_LED_ROW4 GPIO_PIN(0, 24)
|
||||
#define MICROBIT_LED_ROW5 GPIO_PIN(0, 19)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name Button configuration
|
||||
* @{
|
||||
*/
|
||||
#define BTN0_PIN GPIO_PIN(0, 14)
|
||||
#define BTN0_MODE GPIO_IN
|
||||
#define BTN1_PIN GPIO_PIN(0, 23)
|
||||
#define BTN1_MODE GPIO_IN
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name Microphone
|
||||
* @{
|
||||
*/
|
||||
#define RUN_MIC_PIN GPIO_PIN(0, 20)
|
||||
#define MIC_IN_PIN GPIO_PIN(0, 5)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name Speaker
|
||||
* @{
|
||||
*/
|
||||
#define SPEAKER_PIN GPIO_PIN(0, 0)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name LSM303AGR accelerometer/magnetometer
|
||||
* @{
|
||||
*/
|
||||
#define LSM303AGR_PARAM_ACC_ADDR 0x19
|
||||
#define LSM303AGR_PARAM_MAG_ADDR 0x1E
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* BOARD_H */
|
||||
/** @} */
|
53
boards/microbit-v2/include/gpio_params.h
Normal file
53
boards/microbit-v2/include/gpio_params.h
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Inria
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup boards_microbit_v2
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Board specific configuration of direct mapped GPIOs
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
*/
|
||||
|
||||
#ifndef GPIO_PARAMS_H
|
||||
#define GPIO_PARAMS_H
|
||||
|
||||
#include "board.h"
|
||||
#include "saul/periph.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief GPIO pin configuration
|
||||
*/
|
||||
static const saul_gpio_params_t saul_gpio_params[] =
|
||||
{
|
||||
{
|
||||
.name = "Button A",
|
||||
.pin = BTN0_PIN,
|
||||
.mode = BTN0_MODE,
|
||||
.flags = SAUL_GPIO_INVERTED,
|
||||
},
|
||||
{
|
||||
.name = "Button B",
|
||||
.pin = BTN1_PIN,
|
||||
.mode = BTN1_MODE,
|
||||
.flags = SAUL_GPIO_INVERTED,
|
||||
},
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* GPIO_PARAMS_H */
|
||||
/** @} */
|
90
boards/microbit-v2/include/microbit.h
Normal file
90
boards/microbit-v2/include/microbit.h
Normal file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Freie Universität Berlin
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup boards_microbit
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief BBC micro:bit specific LED handling
|
||||
*
|
||||
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||
*/
|
||||
|
||||
#ifndef MICROBIT_H
|
||||
#define MICROBIT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Number of rows of the LED matrix
|
||||
*/
|
||||
#define MICROBIT_MATRIX_ROWS (5U)
|
||||
|
||||
/**
|
||||
* @brief Number of columns of the LED matrix
|
||||
*/
|
||||
#define MICROBIT_MATRIX_COLS (5U)
|
||||
|
||||
/**
|
||||
* @brief Initialize the micro:bit's LED matrix
|
||||
*/
|
||||
void microbit_matrix_init(void);
|
||||
|
||||
/**
|
||||
* @brief Turn on a single LED in the LED matrix
|
||||
*
|
||||
* @param[in] row row of the LED
|
||||
* @param[in] col column of the LED
|
||||
*/
|
||||
void microbit_matrix_on(uint8_t row, uint8_t col);
|
||||
|
||||
/**
|
||||
* @brief Turn off a single LED in the LED matrix
|
||||
*
|
||||
* @param[in] row row of the LED
|
||||
* @param[in] col column of the LED
|
||||
*/
|
||||
void microbit_matrix_off(uint8_t row, uint8_t col);
|
||||
|
||||
/**
|
||||
* @brief Write the given 'image' to the LED matrix
|
||||
*
|
||||
* In the given buffer, each byte represents one LED in the matrix, hence the
|
||||
* buffer MUST be at least 25 byte wide. A byte value of `0` turns an LED off,
|
||||
* while any other value turns it on.
|
||||
*
|
||||
* @param[in] buf new data to display, MUST be at least 25 byte
|
||||
*/
|
||||
void microbit_matrix_set_raw(const uint8_t *buf);
|
||||
|
||||
/**
|
||||
* @brief Write the given character to the matrix, using the Mineplex font
|
||||
*
|
||||
* @param[in] c character to display
|
||||
*/
|
||||
void microbit_matrix_set_char(char c);
|
||||
|
||||
/**
|
||||
* @brief Shift the given string through the LED matrix
|
||||
*
|
||||
* @param[in] str string do display
|
||||
* @param[in] delay delay between each step [in us]
|
||||
*/
|
||||
void microbit_matrix_shift_str(const char *str, uint32_t delay);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* MICROBIT_H */
|
||||
/** @} */
|
122
boards/microbit-v2/include/periph_conf.h
Normal file
122
boards/microbit-v2/include/periph_conf.h
Normal file
@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Inria
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup boards_microbit_v2
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Peripheral configuration for the BBC micro:bit v2
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
*/
|
||||
|
||||
#ifndef PERIPH_CONF_H
|
||||
#define PERIPH_CONF_H
|
||||
|
||||
#include "board.h"
|
||||
#include "periph_cpu.h"
|
||||
#include "cfg_clock_32_0.h"
|
||||
#include "cfg_timer_default.h"
|
||||
#include "cfg_rtt_default.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enable the internal DC/DC converter
|
||||
*/
|
||||
#define NRF5X_ENABLE_DCDC
|
||||
|
||||
/**
|
||||
* @name UART configuration
|
||||
* @{
|
||||
*/
|
||||
static const uart_conf_t uart_config[] = {
|
||||
{ /* Mapped to USB virtual COM port */
|
||||
.dev = NRF_UARTE0,
|
||||
.rx_pin = GPIO_PIN(1, 8),
|
||||
.tx_pin = GPIO_PIN(0, 6),
|
||||
#ifdef MODULE_PERIPH_UART_HW_FC
|
||||
.rts_pin = GPIO_UNDEF,
|
||||
.cts_pin = GPIO_UNDEF,
|
||||
#endif
|
||||
.irqn = UARTE0_UART0_IRQn,
|
||||
},
|
||||
};
|
||||
|
||||
#define UART_0_ISR (isr_uart0)
|
||||
|
||||
#define UART_NUMOF ARRAY_SIZE(uart_config)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name PWM configuration
|
||||
* @{
|
||||
*/
|
||||
static const pwm_conf_t pwm_config[] = {
|
||||
{
|
||||
NRF_PWM0,
|
||||
{
|
||||
SPEAKER_PIN, /* configure Speaker pin as PWM */
|
||||
GPIO_UNDEF,
|
||||
GPIO_UNDEF,
|
||||
GPIO_UNDEF,
|
||||
}
|
||||
},
|
||||
};
|
||||
#define PWM_NUMOF ARRAY_SIZE(pwm_config)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name I2C configuration
|
||||
* @{
|
||||
*/
|
||||
static const i2c_conf_t i2c_config[] = {
|
||||
{ /* Internal I2C */
|
||||
.dev = NRF_TWIM1,
|
||||
.scl = GPIO_PIN(0, 8),
|
||||
.sda = GPIO_PIN(0, 16),
|
||||
.speed = I2C_SPEED_NORMAL
|
||||
},
|
||||
{ /* External I2C */
|
||||
.dev = NRF_TWIM0,
|
||||
.scl = GPIO_PIN(0, 26), /* P19 */
|
||||
.sda = GPIO_PIN(1, 0), /* P20 */
|
||||
.speed = I2C_SPEED_NORMAL
|
||||
},
|
||||
};
|
||||
#define I2C_NUMOF ARRAY_SIZE(i2c_config)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name SPI configuration
|
||||
* @{
|
||||
*/
|
||||
static const spi_conf_t spi_config[] = {
|
||||
{
|
||||
.dev = NRF_SPIM0,
|
||||
.sclk = GPIO_PIN(0, 17), /* P13 */
|
||||
.mosi = GPIO_PIN(0, 13), /* P15 */
|
||||
.miso = GPIO_PIN(0, 1), /* P14 */
|
||||
#ifdef ERRATA_SPI_SINGLE_BYTE_WORKAROUND
|
||||
.ppi = 0,
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
#define SPI_NUMOF ARRAY_SIZE(spi_config)
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* PERIPH_CONF_H */
|
||||
/** @} */
|
1
boards/microbit-v2/microbit/Makefile
Normal file
1
boards/microbit-v2/microbit/Makefile
Normal file
@ -0,0 +1 @@
|
||||
include $(RIOTBASE)/Makefile.base
|
224
boards/microbit-v2/microbit/microbit.c
Normal file
224
boards/microbit-v2/microbit/microbit.c
Normal file
@ -0,0 +1,224 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Freie Universität Berlin
|
||||
* 2021 Inria
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup boards_microbit_v2
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief BBC micro:bit v2 specific LED matrix handling
|
||||
*
|
||||
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "xtimer.h"
|
||||
|
||||
#include "board.h"
|
||||
#include "microbit.h"
|
||||
#include "mineplex.h"
|
||||
#include "periph/gpio.h"
|
||||
#include "periph/timer.h"
|
||||
|
||||
#define ENABLE_DEBUG 0
|
||||
#include "debug.h"
|
||||
|
||||
/**
|
||||
* @brief The visible number of rows and columns of the LED matrix
|
||||
*/
|
||||
#define ROWS MICROBIT_MATRIX_ROWS
|
||||
#define COLS MICROBIT_MATRIX_COLS
|
||||
|
||||
/**
|
||||
* @brief The electrical number of rows and columns
|
||||
*/
|
||||
#define ROWS_HW (5U)
|
||||
#define COLS_HW (5U)
|
||||
|
||||
/**
|
||||
* @brief The refresh rate used for drawing the contents
|
||||
*
|
||||
* We want a refresh rate of at least 50Hz (->20ms), so the LEDs do not flicker.
|
||||
*/
|
||||
#define REFRESH (6000) /* 6ms * 5 rows -> ~55Hz */
|
||||
|
||||
/**
|
||||
* @brief GPIO pins driving the rows
|
||||
*/
|
||||
static const gpio_t rows[ROWS_HW] = {
|
||||
MICROBIT_LED_ROW1,
|
||||
MICROBIT_LED_ROW2,
|
||||
MICROBIT_LED_ROW3,
|
||||
MICROBIT_LED_ROW4,
|
||||
MICROBIT_LED_ROW5,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief GPIO pins driving the columns
|
||||
*/
|
||||
static const gpio_t cols[COLS_HW] = {
|
||||
MICROBIT_LED_COL1,
|
||||
MICROBIT_LED_COL2,
|
||||
MICROBIT_LED_COL3,
|
||||
MICROBIT_LED_COL4,
|
||||
MICROBIT_LED_COL5,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Map electrical layout to visible layout
|
||||
*/
|
||||
static const uint8_t pixmap[5][5] = {
|
||||
{ 0, 1, 2, 3, 4 },
|
||||
{ 5, 6, 7, 8, 9 },
|
||||
{ 10, 11, 12, 13, 14 },
|
||||
{ 15, 16, 17, 18, 19 },
|
||||
{ 20, 21, 22, 23, 24 }
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Buffer holding the current 'image' that is displayed
|
||||
*/
|
||||
static uint8_t framebuf[ROWS_HW * COLS_HW] = { 0 };
|
||||
|
||||
/**
|
||||
* @brief Internal counter to keep track of which row needs to be refreshed
|
||||
* next
|
||||
*/
|
||||
static unsigned cur_row = 0;
|
||||
|
||||
/**
|
||||
* @brief Write a Mineplex encoded character into the given buffer
|
||||
*
|
||||
* @param[in] c character to write
|
||||
* @param[out] buf buffer to write the encoded character into, MUST be able to
|
||||
* hold 25 byte
|
||||
*/
|
||||
static void char2buf(char c, uint8_t *buf)
|
||||
{
|
||||
const uint8_t *raw = mineplex_char(c);
|
||||
|
||||
/* set each row */
|
||||
for (unsigned row = 0; row < ROWS; row++) {
|
||||
for (unsigned col = 0; col < COLS; col++) {
|
||||
buf[(row * COLS) + col] = (raw[row] & (1 << col));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Shift out and replace an image with the next, column by column
|
||||
*
|
||||
* @param[in|out] cur current 'image', will be overwritten
|
||||
* @param[in] next image to shift in
|
||||
* @param[in] delay delay between each column
|
||||
*/
|
||||
static void shift_next(uint8_t *cur, const uint8_t *next, uint32_t delay)
|
||||
{
|
||||
for (unsigned i = 0; i < COLS; i++) {
|
||||
for (unsigned r = 0; r < ROWS; r++) {
|
||||
for (unsigned c = 0; c < (COLS - 1); c++) {
|
||||
cur[(r * COLS) + c] = cur[(r * COLS) + c + 1];
|
||||
}
|
||||
cur[(r * COLS) + COLS - 1] = next[(r * COLS) + i];
|
||||
}
|
||||
microbit_matrix_set_raw((uint8_t *)cur);
|
||||
xtimer_usleep(delay);
|
||||
}
|
||||
}
|
||||
|
||||
static void refresh(void *arg, int channel)
|
||||
{
|
||||
(void)arg;
|
||||
(void)channel;
|
||||
|
||||
/* set next refresh */
|
||||
timer_set(TIMER_DEV(1), 0, REFRESH);
|
||||
|
||||
/* disable current row */
|
||||
gpio_clear(rows[cur_row]);
|
||||
/* goto next row */
|
||||
cur_row = ((++cur_row) < ROWS_HW) ? cur_row : 0;
|
||||
/* setup columns */
|
||||
unsigned base = (COLS_HW * cur_row);
|
||||
for (unsigned i = 0; i < COLS_HW; i++) {
|
||||
gpio_write(cols[i], !(framebuf[base + i]));
|
||||
}
|
||||
/* and finally enable the new row */
|
||||
gpio_set(rows[cur_row]);
|
||||
}
|
||||
|
||||
void microbit_matrix_init(void)
|
||||
{
|
||||
/* initialize rows */
|
||||
for (unsigned i = 0; i < ROWS_HW; i++) {
|
||||
gpio_init(rows[i], GPIO_OUT);
|
||||
gpio_clear(rows[i]);
|
||||
}
|
||||
/* initialize columns */
|
||||
for (unsigned i = 0; i < COLS_HW; i++) {
|
||||
gpio_init(cols[i], GPIO_OUT);
|
||||
gpio_set(cols[i]);
|
||||
}
|
||||
/* and finally initialize and start the refresh timer */
|
||||
timer_init(TIMER_DEV(1), 1000000, refresh, NULL);
|
||||
timer_set(TIMER_DEV(1), 0, REFRESH);
|
||||
}
|
||||
|
||||
void microbit_matrix_on(uint8_t row, uint8_t col)
|
||||
{
|
||||
if ((row >= 5) || (col >= 5)) {
|
||||
return;
|
||||
}
|
||||
|
||||
framebuf[pixmap[row][col]] = 0x01;
|
||||
}
|
||||
|
||||
void microbit_matrix_off(uint8_t row, uint8_t col)
|
||||
{
|
||||
if ((row >= 5) || (col >= 5)) {
|
||||
return;
|
||||
}
|
||||
|
||||
framebuf[pixmap[row][col]] = 0x00;
|
||||
}
|
||||
|
||||
void microbit_matrix_set_raw(const uint8_t *buf)
|
||||
{
|
||||
for (unsigned row = 0; row < ROWS; row++) {
|
||||
for (unsigned col = 0; col < COLS; col++) {
|
||||
framebuf[pixmap[row][col]] = buf[(row * COLS) + col];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void microbit_matrix_set_char(char c)
|
||||
{
|
||||
uint8_t buf[ROWS * COLS];
|
||||
|
||||
char2buf(c, buf);
|
||||
microbit_matrix_set_raw(buf);
|
||||
}
|
||||
|
||||
void microbit_matrix_shift_str(const char *str, uint32_t delay)
|
||||
{
|
||||
uint8_t curbuf[ROWS][COLS];
|
||||
uint8_t newbuf[ROWS][COLS];
|
||||
|
||||
char2buf(' ', (uint8_t *)curbuf);
|
||||
microbit_matrix_set_raw((uint8_t *)curbuf);
|
||||
while (*str) {
|
||||
char2buf(*str++, (uint8_t *)newbuf);
|
||||
shift_next((uint8_t *)curbuf, (uint8_t *)newbuf, delay);
|
||||
}
|
||||
char2buf(' ', (uint8_t *)newbuf);
|
||||
shift_next((uint8_t *)curbuf, (uint8_t *)newbuf, delay);
|
||||
}
|
@ -6,7 +6,7 @@ endif
|
||||
CPU_FAM = nrf52
|
||||
|
||||
# The 802.15.4 radio is not available on all SoCs
|
||||
ifneq (,$(filter nrf52811xxaa nrf52820xxaa rf52833xxaa nrf52840xxaa,$(CPU_MODEL)))
|
||||
ifneq (,$(filter nrf52811xxaa nrf52820xxaa nrf52833xxaa nrf52840xxaa,$(CPU_MODEL)))
|
||||
FEATURES_PROVIDED += radio_nrf802154
|
||||
endif
|
||||
|
||||
|
@ -46,7 +46,7 @@ extern "C" {
|
||||
*
|
||||
* The port definition is used (and zeroed) to suppress compiler warnings
|
||||
*/
|
||||
#ifdef CPU_MODEL_NRF52840XXAA
|
||||
#if !defined(CPU_MODEL_NRF52832XXAA) && !defined(CPU_FAM_NRF51)
|
||||
#define GPIO_PIN(x,y) ((x << 5) | y)
|
||||
#else
|
||||
#define GPIO_PIN(x,y) ((x & 0) | y)
|
||||
|
@ -86,7 +86,7 @@ static inline NRF_GPIO_Type *port(gpio_t pin)
|
||||
*/
|
||||
static inline int pin_num(gpio_t pin)
|
||||
{
|
||||
#ifdef CPU_MODEL_NRF52840XXAA
|
||||
#if !defined(CPU_MODEL_NRF52832XXAA) && !defined(CPU_FAM_NRF51)
|
||||
return (pin & PIN_MASK);
|
||||
#else
|
||||
return (int)pin;
|
||||
@ -184,7 +184,7 @@ int gpio_init_int(gpio_t pin, gpio_mode_t mode, gpio_flank_t flank,
|
||||
/* configure the GPIOTE channel: set even mode, pin and active flank */
|
||||
NRF_GPIOTE->CONFIG[_pin_index] = (GPIOTE_CONFIG_MODE_Event |
|
||||
(pin_num(pin) << GPIOTE_CONFIG_PSEL_Pos) |
|
||||
#ifdef CPU_MODEL_NRF52840XXAA
|
||||
#if !defined(CPU_MODEL_NRF52832XXAA) && !defined(CPU_FAM_NRF51)
|
||||
((pin & PORT_BIT) << 8) |
|
||||
#endif
|
||||
(flank << GPIOTE_CONFIG_POLARITY_Pos));
|
||||
|
@ -85,7 +85,7 @@ static inline NRF_UARTE_Type *dev(uart_t uart)
|
||||
*/
|
||||
static uart_isr_ctx_t isr_ctx;
|
||||
|
||||
#endif /* CPU_MODEL_NRF52840XXAA || CPU_MODEL_NRF52811XXAA */
|
||||
#endif /* !CPU_MODEL_NRF52832XXAA && !CPU_FAM_NRF51 */
|
||||
|
||||
int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
|
||||
{
|
||||
@ -415,7 +415,7 @@ static inline void irq_handler(uart_t uart)
|
||||
cortexm_isr_end();
|
||||
}
|
||||
|
||||
#endif /* CPU_MODEL_NRF52840XXAA || CPU_MODEL_NRF5211XXAA */
|
||||
#endif /* !CPU_MODEL_NRF52832XXAA && !CPU_FAM_NRF51 */
|
||||
|
||||
#ifdef UART_0_ISR
|
||||
void UART_0_ISR(void)
|
||||
|
@ -36,7 +36,7 @@ USEMODULE += saul_default
|
||||
|
||||
BOARD_PROVIDES_NETIF := acd52832 adafruit-clue airfy-beacon atmega256rfr2-xpro \
|
||||
arduino-nano-33-ble avr-rss2 b-l072z-lrwan1 cc2538dk dwm1001 fox \
|
||||
derfmega128 derfmega256 hamilton iotlab-m3 iotlab-a8-m3 lobaro-lorabox lsn50 mulle microbit msba2 \
|
||||
derfmega128 derfmega256 hamilton iotlab-m3 iotlab-a8-m3 lobaro-lorabox lsn50 mulle microbit microbit-v2 msba2 \
|
||||
microduino-corerf native nrf51dk nrf51dongle nrf52dk nrf52840dk nrf52840-mdk nrf52840dongle nrf6310 \
|
||||
nucleo-f207zg nucleo-f767zi openmote-b openmote-cc2538 pba-d-01-kw2x remote-pa \
|
||||
remote-reva ruuvitag same54-xpro samr21-xpro samr30-xpro spark-core telosb thingy52 yunjia-nrf51822 z1 \
|
||||
|
@ -3,7 +3,7 @@ BOARD ?= microbit
|
||||
include ../Makefile.tests_common
|
||||
|
||||
# This test application is for the BBC micro:bit only
|
||||
BOARD_WHITELIST := microbit
|
||||
BOARD_WHITELIST := microbit microbit-v2
|
||||
|
||||
# We want to test the microbit support module
|
||||
USEMODULE += microbit
|
||||
|
Loading…
Reference in New Issue
Block a user