Initial InfiniSim project
This commit is contained in:
95
sim/nrfx/drivers/include/nrfx_twi.h
Normal file
95
sim/nrfx/drivers/include/nrfx_twi.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* Copyright (c) 2015 - 2019, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NRFX_TWI_H__
|
||||
#define NRFX_TWI_H__
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
/**
|
||||
* @brief I2C compatible Two-Wire Master Interface with EasyDMA 0 (TWIM0)
|
||||
*/
|
||||
|
||||
struct NRF_TWIM_Type { /*!< (@ 0x40003000) TWIM0 Structure */
|
||||
uint32_t TASKS_STARTRX; /*!< (@ 0x00000000) Start TWI receive sequence */
|
||||
uint32_t RESERVED;
|
||||
uint32_t TASKS_STARTTX; /*!< (@ 0x00000008) Start TWI transmit sequence */
|
||||
uint32_t RESERVED1[2];
|
||||
uint32_t TASKS_STOP; /*!< (@ 0x00000014) Stop TWI transaction. Must be issued while the
|
||||
TWI master is not suspended. */
|
||||
uint32_t RESERVED2;
|
||||
uint32_t TASKS_SUSPEND; /*!< (@ 0x0000001C) Suspend TWI transaction */
|
||||
uint32_t TASKS_RESUME; /*!< (@ 0x00000020) Resume TWI transaction */
|
||||
uint32_t RESERVED3[56];
|
||||
uint32_t EVENTS_STOPPED; /*!< (@ 0x00000104) TWI stopped */
|
||||
uint32_t RESERVED4[7];
|
||||
uint32_t EVENTS_ERROR; /*!< (@ 0x00000124) TWI error */
|
||||
uint32_t RESERVED5[8];
|
||||
uint32_t EVENTS_SUSPENDED; /*!< (@ 0x00000148) Last byte has been sent out after the SUSPEND
|
||||
task has been issued, TWI traffic is now
|
||||
suspended. */
|
||||
uint32_t EVENTS_RXSTARTED; /*!< (@ 0x0000014C) Receive sequence started */
|
||||
uint32_t EVENTS_TXSTARTED; /*!< (@ 0x00000150) Transmit sequence started */
|
||||
uint32_t RESERVED6[2];
|
||||
uint32_t EVENTS_LASTRX; /*!< (@ 0x0000015C) Byte boundary, starting to receive the last byte */
|
||||
uint32_t EVENTS_LASTTX; /*!< (@ 0x00000160) Byte boundary, starting to transmit the last
|
||||
byte */
|
||||
uint32_t RESERVED7[39];
|
||||
uint32_t SHORTS; /*!< (@ 0x00000200) Shortcut register */
|
||||
uint32_t RESERVED8[63];
|
||||
uint32_t INTEN; /*!< (@ 0x00000300) Enable or disable interrupt */
|
||||
uint32_t INTENSET; /*!< (@ 0x00000304) Enable interrupt */
|
||||
uint32_t INTENCLR; /*!< (@ 0x00000308) Disable interrupt */
|
||||
uint32_t RESERVED9[110];
|
||||
uint32_t ERRORSRC; /*!< (@ 0x000004C4) Error source */
|
||||
uint32_t RESERVED10[14];
|
||||
uint32_t ENABLE; /*!< (@ 0x00000500) Enable TWIM */
|
||||
uint32_t RESERVED11;
|
||||
/// TWIM_PSEL_Type PSEL; /*!< (@ 0x00000508) Unspecified */
|
||||
uint32_t RESERVED12[5];
|
||||
uint32_t FREQUENCY; /*!< (@ 0x00000524) TWI frequency */
|
||||
uint32_t RESERVED13[3];
|
||||
// TWIM_RXD_Type RXD; /*!< (@ 0x00000534) RXD EasyDMA channel */
|
||||
// TWIM_TXD_Type TXD; /*!< (@ 0x00000544) TXD EasyDMA channel */
|
||||
uint32_t RESERVED14[13];
|
||||
uint32_t ADDRESS; /*!< (@ 0x00000588) Address used in the TWI transfer */
|
||||
}; /*!< Size = 1420 (0x58c) */
|
||||
|
||||
#endif // NRFX_TWI_H__
|
33
sim/nrfx/hal/nrf_gpio.cpp
Normal file
33
sim/nrfx/hal/nrf_gpio.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "hal/nrf_gpio.h"
|
||||
|
||||
#include "drivers/PinMap.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <stdexcept>
|
||||
|
||||
void nrf_gpio_cfg_default(uint32_t pin_number) {}
|
||||
void nrf_gpio_pin_set(uint32_t pin_number) {}
|
||||
uint32_t nrf_gpio_pin_read(uint32_t pin_number)
|
||||
{
|
||||
if (pin_number == Pinetime::PinMap::Button) {
|
||||
int x, y;
|
||||
uint32_t buttons = SDL_GetMouseState(&x, &y);
|
||||
bool right_click = (buttons & SDL_BUTTON_RMASK) != 0;
|
||||
return right_click;
|
||||
}
|
||||
throw std::runtime_error("nrf_gpio_pin_read: unhandled pin_number: " + std::to_string(pin_number));
|
||||
return 0;
|
||||
}
|
||||
|
||||
void nrf_gpio_cfg_output(uint32_t pin_number) {}
|
||||
void nrf_gpio_pin_clear(uint32_t pin_number) {}
|
||||
void nrf_gpio_range_cfg_input(uint32_t pin_range_start,
|
||||
uint32_t pin_range_end,
|
||||
nrf_gpio_pin_pull_t pull_config) {}
|
||||
void nrf_gpio_cfg_input(uint32_t pin_number, nrf_gpio_pin_pull_t pull_config) {}
|
||||
|
||||
void nrfx_gpiote_in_init(uint32_t pin_number, nrfx_gpiote_in_config_t *config, nrfx_gpiote_event_handler_t) {}
|
||||
void nrfx_gpiote_in_event_enable(uint32_t pin_number, bool enable) {}
|
||||
void nrf_gpio_cfg_sense_input(uint32_t pin_number, nrf_gpio_pin_pull_t pin_pull, nrf_gpio_pin_sense_t sense) {}
|
||||
|
||||
void APP_GPIOTE_INIT(uint32_t max_users) {}
|
150
sim/nrfx/hal/nrf_gpio.h
Normal file
150
sim/nrfx/hal/nrf_gpio.h
Normal file
@@ -0,0 +1,150 @@
|
||||
/**
|
||||
* Copyright (c) 2015 - 2019, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NRF_GPIO_H__
|
||||
#define NRF_GPIO_H__
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
/**
|
||||
* @brief Enumerator used for selecting the pin to be pulled down or up at the time of pin configuration.
|
||||
*/
|
||||
// lv_sim: values copied from nrf52810_bifiellds.h
|
||||
enum nrf_gpio_pin_pull_t
|
||||
{
|
||||
NRF_GPIO_PIN_NOPULL = 0, // GPIO_PIN_CNF_PULL_Disabled, ///< Pin pull-up resistor disabled.
|
||||
NRF_GPIO_PIN_PULLDOWN = 1, // GPIO_PIN_CNF_PULL_Pulldown, ///< Pin pull-down resistor enabled.
|
||||
NRF_GPIO_PIN_PULLUP = 3, // GPIO_PIN_CNF_PULL_Pullup, ///< Pin pull-up resistor enabled.
|
||||
};
|
||||
constexpr uint16_t GPIO_PIN_CNF_PULL_Pulldown = 1;
|
||||
constexpr uint16_t GPIO_PIN_CNF_PULL_Pullup = 3;
|
||||
|
||||
using nrf_gpiote_polarity_t = uint32_t;
|
||||
constexpr uint16_t NRF_GPIOTE_POLARITY_HITOLO = 2;
|
||||
constexpr uint16_t NRF_GPIOTE_POLARITY_TOGGLE = 3;
|
||||
|
||||
using nrfx_gpiote_pin_t = uint32_t;
|
||||
typedef void (*nrfx_gpiote_event_handler_t)(nrfx_gpiote_pin_t, nrf_gpiote_polarity_t);
|
||||
|
||||
using nrf_gpio_pin_sense_t = uint32_t;
|
||||
constexpr uint16_t GPIO_PIN_CNF_SENSE_Low = 3;
|
||||
|
||||
struct nrfx_gpiote_in_config_t {
|
||||
bool skip_gpio_setup = false;
|
||||
bool hi_accuracy = false;
|
||||
bool is_watcher = false;
|
||||
nrf_gpiote_polarity_t sense;
|
||||
nrf_gpio_pin_pull_t pull;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Function for resetting pin configuration to its default state.
|
||||
*
|
||||
* @param pin_number Specifies the pin number.
|
||||
*/
|
||||
void nrf_gpio_cfg_default(uint32_t pin_number);
|
||||
|
||||
/**
|
||||
* @brief Function for setting a GPIO pin.
|
||||
*
|
||||
* Note that the pin must be configured as an output for this function to have any effect.
|
||||
*
|
||||
* @param pin_number Specifies the pin number to set.
|
||||
*/
|
||||
void nrf_gpio_pin_set(uint32_t pin_number);
|
||||
|
||||
// read pin stub, intended to forward right mouse button as PinMap::Button
|
||||
uint32_t nrf_gpio_pin_read(uint32_t pin_number);
|
||||
|
||||
/**
|
||||
* @brief Function for configuring the given GPIO pin number as output, hiding inner details.
|
||||
* This function can be used to configure a pin as simple output with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases).
|
||||
*
|
||||
* @param pin_number Specifies the pin number.
|
||||
*
|
||||
* @note Sense capability on the pin is disabled and input is disconnected from the buffer as the pins are configured as output.
|
||||
*/
|
||||
void nrf_gpio_cfg_output(uint32_t pin_number);
|
||||
|
||||
/**
|
||||
* @brief Function for clearing a GPIO pin.
|
||||
*
|
||||
* Note that the pin must be configured as an output for this
|
||||
* function to have any effect.
|
||||
*
|
||||
* @param pin_number Specifies the pin number to clear.
|
||||
*/
|
||||
void nrf_gpio_pin_clear(uint32_t pin_number);
|
||||
|
||||
/**
|
||||
* @brief Function for configuring the GPIO pin range as input pins with given initial value set, hiding inner details.
|
||||
* This function can be used to configure pin range as simple input.
|
||||
*
|
||||
* @param pin_range_start Specifies the start number (inclusive) in the range of pin numbers to be configured (allowed values 0-30).
|
||||
*
|
||||
* @param pin_range_end Specifies the end number (inclusive) in the range of pin numbers to be configured (allowed values 0-30).
|
||||
*
|
||||
* @param pull_config State of the pin range pull resistor (no pull, pulled down, or pulled high).
|
||||
*
|
||||
* @note For configuring only one pin as input, use @ref nrf_gpio_cfg_input.
|
||||
* Sense capability on the pin is disabled and input is connected to buffer so that the GPIO->IN register is readable.
|
||||
*/
|
||||
void nrf_gpio_range_cfg_input(uint32_t pin_range_start,
|
||||
uint32_t pin_range_end,
|
||||
nrf_gpio_pin_pull_t pull_config);
|
||||
|
||||
/**
|
||||
* @brief Function for configuring the given GPIO pin number as input, hiding inner details.
|
||||
* This function can be used to configure a pin as simple input.
|
||||
*
|
||||
* @param pin_number Specifies the pin number.
|
||||
* @param pull_config State of the pin range pull resistor (no pull, pulled down, or pulled high).
|
||||
*
|
||||
* @note Sense capability on the pin is disabled and input is connected to buffer so that the GPIO->IN register is readable.
|
||||
*/
|
||||
void nrf_gpio_cfg_input(uint32_t pin_number, nrf_gpio_pin_pull_t pull_config);
|
||||
|
||||
void nrfx_gpiote_in_init(uint32_t pin_number, nrfx_gpiote_in_config_t *config, nrfx_gpiote_event_handler_t);
|
||||
void nrfx_gpiote_in_event_enable(uint32_t pin_number, bool enable);
|
||||
void nrf_gpio_cfg_sense_input(uint32_t pin_number, nrf_gpio_pin_pull_t pin_pull, nrf_gpio_pin_sense_t sense);
|
||||
|
||||
void APP_GPIOTE_INIT(uint32_t max_users);
|
||||
|
||||
#endif // NRF_GPIO_H__
|
15
sim/nrfx/hal/nrf_rtc.cpp
Normal file
15
sim/nrfx/hal/nrf_rtc.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "hal/nrf_rtc.h"
|
||||
|
||||
#include "task.h"
|
||||
#include <chrono>
|
||||
#include <stdexcept>
|
||||
|
||||
uint32_t nrf_rtc_counter_get(NRF_RTC_Type p_reg)
|
||||
{
|
||||
if (p_reg == portNRF_RTC_REG) {
|
||||
TickType_t ticks_now = xTaskGetTickCount();
|
||||
return ticks_now;
|
||||
}
|
||||
throw std::runtime_error("nrf_rtc_counter_get: unhandled NRF_RTC_Type: " + std::to_string(p_reg));
|
||||
return 0;
|
||||
}
|
7
sim/nrfx/hal/nrf_rtc.h
Normal file
7
sim/nrfx/hal/nrf_rtc.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "portmacro_cmsis.h"
|
||||
|
||||
// normal version has pointer to register 'NRF_RTC_Type * p_reg', but we just simulate
|
||||
// the return value according to known register pointer
|
||||
uint32_t nrf_rtc_counter_get(NRF_RTC_Type p_reg);
|
3
sim/nrfx/hal/nrfx_gpiote.h
Normal file
3
sim/nrfx/hal/nrfx_gpiote.h
Normal file
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#include <hal/nrf_gpio.h>
|
54
sim/nrfx/nrfx_log.h
Normal file
54
sim/nrfx/nrfx_log.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2019, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/**@file
|
||||
*
|
||||
* @defgroup nrf_log Logger module
|
||||
* @{
|
||||
* @ingroup app_common
|
||||
*
|
||||
* @brief The nrfx_log module interface.
|
||||
*/
|
||||
|
||||
#ifndef NRFX_LOG_H_
|
||||
#define NRFX_LOG_H_
|
||||
|
||||
#include "libraries/log/nrf_log.h"
|
||||
|
||||
#endif // NRFX_LOG_H_
|
Reference in New Issue
Block a user