Merge branch 'master' into nrf52_uart_io

This commit is contained in:
Dan Halbert 2018-10-03 13:31:48 -04:00 committed by GitHub
commit 6049776b26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 82 additions and 75 deletions

View File

@ -2007,19 +2007,19 @@ msgstr ""
msgid "Buffer must be at least length 1" msgid "Buffer must be at least length 1"
msgstr "" msgstr ""
#: shared-bindings/bitbangio/SPI.c:151 shared-bindings/busio/SPI.c:168 #: shared-bindings/bitbangio/SPI.c:151 shared-bindings/busio/SPI.c:175
msgid "Invalid polarity" msgid "Invalid polarity"
msgstr "" msgstr ""
#: shared-bindings/bitbangio/SPI.c:155 shared-bindings/busio/SPI.c:172 #: shared-bindings/bitbangio/SPI.c:155 shared-bindings/busio/SPI.c:179
msgid "Invalid phase" msgid "Invalid phase"
msgstr "" msgstr ""
#: shared-bindings/bitbangio/SPI.c:159 shared-bindings/busio/SPI.c:176 #: shared-bindings/bitbangio/SPI.c:159 shared-bindings/busio/SPI.c:183
msgid "Invalid number of bits" msgid "Invalid number of bits"
msgstr "" msgstr ""
#: shared-bindings/bitbangio/SPI.c:284 shared-bindings/busio/SPI.c:341 #: shared-bindings/bitbangio/SPI.c:284 shared-bindings/busio/SPI.c:348
msgid "buffer slices must be of equal length" msgid "buffer slices must be of equal length"
msgstr "" msgstr ""

View File

@ -2020,19 +2020,19 @@ msgstr ""
msgid "Buffer must be at least length 1" msgid "Buffer must be at least length 1"
msgstr "" msgstr ""
#: shared-bindings/bitbangio/SPI.c:151 shared-bindings/busio/SPI.c:168 #: shared-bindings/bitbangio/SPI.c:151 shared-bindings/busio/SPI.c:175
msgid "Invalid polarity" msgid "Invalid polarity"
msgstr "" msgstr ""
#: shared-bindings/bitbangio/SPI.c:155 shared-bindings/busio/SPI.c:172 #: shared-bindings/bitbangio/SPI.c:155 shared-bindings/busio/SPI.c:179
msgid "Invalid phase" msgid "Invalid phase"
msgstr "" msgstr ""
#: shared-bindings/bitbangio/SPI.c:159 shared-bindings/busio/SPI.c:176 #: shared-bindings/bitbangio/SPI.c:159 shared-bindings/busio/SPI.c:183
msgid "Invalid number of bits" msgid "Invalid number of bits"
msgstr "" msgstr ""
#: shared-bindings/bitbangio/SPI.c:284 shared-bindings/busio/SPI.c:341 #: shared-bindings/bitbangio/SPI.c:284 shared-bindings/busio/SPI.c:348
msgid "buffer slices must be of equal length" msgid "buffer slices must be of equal length"
msgstr "" msgstr ""

View File

@ -2007,19 +2007,19 @@ msgstr ""
msgid "Buffer must be at least length 1" msgid "Buffer must be at least length 1"
msgstr "" msgstr ""
#: shared-bindings/bitbangio/SPI.c:151 shared-bindings/busio/SPI.c:168 #: shared-bindings/bitbangio/SPI.c:151 shared-bindings/busio/SPI.c:175
msgid "Invalid polarity" msgid "Invalid polarity"
msgstr "" msgstr ""
#: shared-bindings/bitbangio/SPI.c:155 shared-bindings/busio/SPI.c:172 #: shared-bindings/bitbangio/SPI.c:155 shared-bindings/busio/SPI.c:179
msgid "Invalid phase" msgid "Invalid phase"
msgstr "" msgstr ""
#: shared-bindings/bitbangio/SPI.c:159 shared-bindings/busio/SPI.c:176 #: shared-bindings/bitbangio/SPI.c:159 shared-bindings/busio/SPI.c:183
msgid "Invalid number of bits" msgid "Invalid number of bits"
msgstr "" msgstr ""
#: shared-bindings/bitbangio/SPI.c:284 shared-bindings/busio/SPI.c:341 #: shared-bindings/bitbangio/SPI.c:284 shared-bindings/busio/SPI.c:348
msgid "buffer slices must be of equal length" msgid "buffer slices must be of equal length"
msgstr "" msgstr ""

View File

@ -2053,19 +2053,19 @@ msgstr ""
msgid "Buffer must be at least length 1" msgid "Buffer must be at least length 1"
msgstr "" msgstr ""
#: shared-bindings/bitbangio/SPI.c:151 shared-bindings/busio/SPI.c:168 #: shared-bindings/bitbangio/SPI.c:151 shared-bindings/busio/SPI.c:175
msgid "Invalid polarity" msgid "Invalid polarity"
msgstr "" msgstr ""
#: shared-bindings/bitbangio/SPI.c:155 shared-bindings/busio/SPI.c:172 #: shared-bindings/bitbangio/SPI.c:155 shared-bindings/busio/SPI.c:179
msgid "Invalid phase" msgid "Invalid phase"
msgstr "" msgstr ""
#: shared-bindings/bitbangio/SPI.c:159 shared-bindings/busio/SPI.c:176 #: shared-bindings/bitbangio/SPI.c:159 shared-bindings/busio/SPI.c:183
msgid "Invalid number of bits" msgid "Invalid number of bits"
msgstr "" msgstr ""
#: shared-bindings/bitbangio/SPI.c:284 shared-bindings/busio/SPI.c:341 #: shared-bindings/bitbangio/SPI.c:284 shared-bindings/busio/SPI.c:348
msgid "buffer slices must be of equal length" msgid "buffer slices must be of equal length"
msgstr "" msgstr ""

View File

@ -745,7 +745,7 @@ msgstr "hindi sinusuportahan ang bytes > 8 bits"
#: ports/nrf/common-hal/busio/UART.c:364 #: ports/nrf/common-hal/busio/UART.c:364
#, fuzzy #, fuzzy
msgid "busio.UART not available" msgid "busio.UART not available"
msgstr "hindi pa implemented ang busio.UART" msgstr ""
#: ports/nrf/common-hal/microcontroller/Processor.c:49 #: ports/nrf/common-hal/microcontroller/Processor.c:49
#, c-format #, c-format
@ -2050,19 +2050,19 @@ msgstr "Function nangangailangan ng lock"
msgid "Buffer must be at least length 1" msgid "Buffer must be at least length 1"
msgstr "Buffer dapat ay hindi baba sa 1 na haba" msgstr "Buffer dapat ay hindi baba sa 1 na haba"
#: shared-bindings/bitbangio/SPI.c:151 shared-bindings/busio/SPI.c:168 #: shared-bindings/bitbangio/SPI.c:151 shared-bindings/busio/SPI.c:175
msgid "Invalid polarity" msgid "Invalid polarity"
msgstr "Mali ang polarity" msgstr "Mali ang polarity"
#: shared-bindings/bitbangio/SPI.c:155 shared-bindings/busio/SPI.c:172 #: shared-bindings/bitbangio/SPI.c:155 shared-bindings/busio/SPI.c:179
msgid "Invalid phase" msgid "Invalid phase"
msgstr "Mali ang phase" msgstr "Mali ang phase"
#: shared-bindings/bitbangio/SPI.c:159 shared-bindings/busio/SPI.c:176 #: shared-bindings/bitbangio/SPI.c:159 shared-bindings/busio/SPI.c:183
msgid "Invalid number of bits" msgid "Invalid number of bits"
msgstr "Mali ang bilang ng bits" msgstr "Mali ang bilang ng bits"
#: shared-bindings/bitbangio/SPI.c:284 shared-bindings/busio/SPI.c:341 #: shared-bindings/bitbangio/SPI.c:284 shared-bindings/busio/SPI.c:348
msgid "buffer slices must be of equal length" msgid "buffer slices must be of equal length"
msgstr "aarehas na haba dapat ang buffer slices" msgstr "aarehas na haba dapat ang buffer slices"

View File

@ -741,7 +741,7 @@ msgstr "octets > 8 bits non supporté"
#: ports/nrf/common-hal/busio/UART.c:364 #: ports/nrf/common-hal/busio/UART.c:364
#, fuzzy #, fuzzy
msgid "busio.UART not available" msgid "busio.UART not available"
msgstr "busio.UART pas encore implémenté" msgstr "busio.UART n'est pas disponible"
#: ports/nrf/common-hal/microcontroller/Processor.c:49 #: ports/nrf/common-hal/microcontroller/Processor.c:49
#, c-format #, c-format
@ -2041,19 +2041,19 @@ msgstr "La fonction nécessite un verrou"
msgid "Buffer must be at least length 1" msgid "Buffer must be at least length 1"
msgstr "Le tampon doit être de longueur au moins 1" msgstr "Le tampon doit être de longueur au moins 1"
#: shared-bindings/bitbangio/SPI.c:151 shared-bindings/busio/SPI.c:168 #: shared-bindings/bitbangio/SPI.c:151 shared-bindings/busio/SPI.c:175
msgid "Invalid polarity" msgid "Invalid polarity"
msgstr "Polarité invalide" msgstr "Polarité invalide"
#: shared-bindings/bitbangio/SPI.c:155 shared-bindings/busio/SPI.c:172 #: shared-bindings/bitbangio/SPI.c:155 shared-bindings/busio/SPI.c:179
msgid "Invalid phase" msgid "Invalid phase"
msgstr "Phase invalide" msgstr "Phase invalide"
#: shared-bindings/bitbangio/SPI.c:159 shared-bindings/busio/SPI.c:176 #: shared-bindings/bitbangio/SPI.c:159 shared-bindings/busio/SPI.c:183
msgid "Invalid number of bits" msgid "Invalid number of bits"
msgstr "Nombre de bits invalide" msgstr "Nombre de bits invalide"
#: shared-bindings/bitbangio/SPI.c:284 shared-bindings/busio/SPI.c:341 #: shared-bindings/bitbangio/SPI.c:284 shared-bindings/busio/SPI.c:348
msgid "buffer slices must be of equal length" msgid "buffer slices must be of equal length"
msgstr "les slices de tampon doivent être de longueurs égales" msgstr "les slices de tampon doivent être de longueurs égales"

View File

@ -65,40 +65,40 @@ void spi_reset(void) {
} }
} }
// Convert frequency to clock-speed-dependent value // Convert frequency to clock-speed-dependent value. Choose the next lower baudrate if in between
// available baudrates.
static nrf_spim_frequency_t baudrate_to_spim_frequency(const uint32_t baudrate) { static nrf_spim_frequency_t baudrate_to_spim_frequency(const uint32_t baudrate) {
if (baudrate <= 125000) {
return NRF_SPIM_FREQ_125K;
}
if (baudrate <= 250000) {
return NRF_SPIM_FREQ_250K;
}
if (baudrate <= 500000) {
return NRF_SPIM_FREQ_500K;
}
if (baudrate <= 1000000) {
return NRF_SPIM_FREQ_1M;
}
if (baudrate <= 2000000) {
return NRF_SPIM_FREQ_2M;
}
if (baudrate <= 4000000) {
return NRF_SPIM_FREQ_4M;
}
if (baudrate <= 8000000) {
return NRF_SPIM_FREQ_8M;
}
#ifdef SPIM_FREQUENCY_FREQUENCY_M16
if (baudrate <= 16000000) {
return NRF_SPIM_FREQ_16M;
}
#endif
static const struct {
const uint32_t boundary;
nrf_spim_frequency_t spim_frequency;
} baudrate_map[] = {
#ifdef SPIM_FREQUENCY_FREQUENCY_M32 #ifdef SPIM_FREQUENCY_FREQUENCY_M32
return NRF_SPIM_FREQ_32M; { 32000000, NRF_SPIM_FREQ_32M },
#else
return NRF_SPIM_FREQ_8M;
#endif #endif
#ifdef SPIM_FREQUENCY_FREQUENCY_M16
{ 16000000, NRF_SPIM_FREQ_16M },
#endif
{ 8000000, NRF_SPIM_FREQ_8M },
{ 4000000, NRF_SPIM_FREQ_4M },
{ 2000000, NRF_SPIM_FREQ_2M },
{ 1000000, NRF_SPIM_FREQ_1M },
{ 500000, NRF_SPIM_FREQ_500K },
{ 250000, NRF_SPIM_FREQ_250K },
{ 0, NRF_SPIM_FREQ_125K },
};
size_t i = 0;
uint32_t boundary;
do {
boundary = baudrate_map[i].boundary;
if (baudrate >= boundary) {
return baudrate_map[i].spim_frequency;
}
i++;
} while (boundary != 0);
// Should not get here.
return 0;
} }
void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t * clock, const mcu_pin_obj_t * mosi, const mcu_pin_obj_t * miso) { void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t * clock, const mcu_pin_obj_t * mosi, const mcu_pin_obj_t * miso) {
@ -168,26 +168,26 @@ void common_hal_busio_spi_deinit(busio_spi_obj_t *self) {
} }
bool common_hal_busio_spi_configure(busio_spi_obj_t *self, uint32_t baudrate, uint8_t polarity, uint8_t phase, uint8_t bits) { bool common_hal_busio_spi_configure(busio_spi_obj_t *self, uint32_t baudrate, uint8_t polarity, uint8_t phase, uint8_t bits) {
// nrf52 does not support 16 bit // nrf52 does not support 16 bit
if (bits != 8) if (bits != 8) {
return false; return false;
}
if (baudrate > self->spim_peripheral->max_frequency_MHz * 1000000) { // Set desired frequency, rounding down, and don't go above available frequency for this SPIM.
mp_raise_ValueError(translate("Baud rate too high for this SPI peripheral")); nrf_spim_frequency_set(self->spim_peripheral->spim.p_reg,
return false; baudrate_to_spim_frequency(MIN(baudrate,
} self->spim_peripheral->max_frequency_MHz * 1000000)));
nrf_spim_frequency_set(self->spim_peripheral->spim.p_reg, baudrate_to_spim_frequency(baudrate));
nrf_spim_mode_t mode = NRF_SPIM_MODE_0; nrf_spim_mode_t mode = NRF_SPIM_MODE_0;
if (polarity) { if (polarity) {
mode = (phase) ? NRF_SPIM_MODE_3 : NRF_SPIM_MODE_2; mode = (phase) ? NRF_SPIM_MODE_3 : NRF_SPIM_MODE_2;
} else { } else {
mode = (phase) ? NRF_SPIM_MODE_1 : NRF_SPIM_MODE_0; mode = (phase) ? NRF_SPIM_MODE_1 : NRF_SPIM_MODE_0;
} }
nrf_spim_configure(self->spim_peripheral->spim.p_reg, mode, NRF_SPIM_BIT_ORDER_MSB_FIRST); nrf_spim_configure(self->spim_peripheral->spim.p_reg, mode, NRF_SPIM_BIT_ORDER_MSB_FIRST);
return true; return true;
} }
bool common_hal_busio_spi_try_lock(busio_spi_obj_t *self) { bool common_hal_busio_spi_try_lock(busio_spi_obj_t *self) {

View File

@ -136,19 +136,26 @@ static void check_lock(busio_spi_obj_t *self) {
//| .. method:: SPI.configure(\*, baudrate=100000, polarity=0, phase=0, bits=8) //| .. method:: SPI.configure(\*, baudrate=100000, polarity=0, phase=0, bits=8)
//| //|
//| Configures the SPI bus. Only valid when locked. //| Configures the SPI bus. The SPI object must be locked.
//| //|
//| :param int baudrate: the desired clock rate in Hertz. The actual clock rate may be higher or lower //| :param int baudrate: the desired clock rate in Hertz. The actual clock rate may be higher or lower
//| due to the granularity of available clock settings. //| due to the granularity of available clock settings.
//| Check the `frequency` attribute for the actual clock rate. //| Check the `frequency` attribute for the actual clock rate.
//| **Note:** on the SAMD21, it is possible to set the baud rate to 24 MHz, but that
//| speed is not guaranteed to work. 12 MHz is the next available lower speed, and is
//| within spec for the SAMD21.
//| :param int polarity: the base state of the clock line (0 or 1) //| :param int polarity: the base state of the clock line (0 or 1)
//| :param int phase: the edge of the clock that data is captured. First (0) //| :param int phase: the edge of the clock that data is captured. First (0)
//| or second (1). Rising or falling depends on clock polarity. //| or second (1). Rising or falling depends on clock polarity.
//| :param int bits: the number of bits per word //| :param int bits: the number of bits per word
//| //|
//| .. note:: On the SAMD21, it is possible to set the baudrate to 24 MHz, but that
//| speed is not guaranteed to work. 12 MHz is the next available lower speed, and is
//| within spec for the SAMD21.
//|
//| .. note:: On the nRF52832, these baudrates are available: 125kHz, 250kHz, 1MHz, 2MHz, 4MHz,
//| and 8MHz. On the nRF52840, 16MHz and 32MHz are also available, but only on the first
//| `busio.SPI` object you create. Two more ``busio.SPI`` objects can be created, but they are restricted
//| to 8MHz maximum. This is a hardware restriction: there is only one high-speed SPI peripheral.
//| If you pick a a baudrate other than one of these, the nearest lower
//| baudrate will be chosen, with a minimum of 125kHz.
STATIC mp_obj_t busio_spi_configure(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { STATIC mp_obj_t busio_spi_configure(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_baudrate, ARG_polarity, ARG_phase, ARG_bits }; enum { ARG_baudrate, ARG_polarity, ARG_phase, ARG_bits };
static const mp_arg_t allowed_args[] = { static const mp_arg_t allowed_args[] = {