Skip to content

Instantly share code, notes, and snippets.

@electronut
electronut / stm32-returns-2.c
Last active October 29, 2017 07:39
stm32-returns-2
Conway64 conway(&hspi2);
int main(void)
{
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
@electronut
electronut / stm32-returns-1.sh
Created October 29, 2017 07:29
stm32-returns-1
$ tree -L 2
.
├── Debug
├── Drivers
│   ├── CMSIS
│   └── STM32F1xx_HAL_Driver
├── Inc
│   ├── FreeRTOSConfig.h
│   ├── main.h
│   ├── stm32f1xx_hal_conf.h
@electronut
electronut / main6.c
Created August 19, 2017 03:16
NUS I2s
volatile uint8_t g_demo_mode = 0;
volatile bool g_i2s_start = true;
volatile bool g_i2s_running = false;
static void nus_data_handler(ble_nus_t * p_nus, uint8_t * p_data, uint16_t length)
{
switch(p_data[0]) {
case '1':
{
g_demo_mode = 0;
@electronut
electronut / main5.c
Created August 19, 2017 03:14
main loop i2s
for (;;)
{
// start I2S
if(g_i2s_start && !g_i2s_running) {
err_code = nrf_drv_i2s_start(0, m_buffer_tx, I2S_BUFFER_SIZE, 0);
APP_ERROR_CHECK(err_code);
g_i2s_running = true;
}
// stop I2S
@electronut
electronut / main5.c
Created August 18, 2017 07:22
caclChannelValue
uint32_t caclChannelValue(uint8_t level)
{
uint32_t val = 0;
// 0
if(level == 0) {
val = 0x88888888;
}
// 255
else if (level == 255) {
@electronut
electronut / main4.c
Created August 18, 2017 07:21
set led data
void set_led_data()
{
for(int i = 0; i < 3*NLEDS; i += 3) {
if (i == 3*nled) {
switch(g_demo_mode)
{
case 0:
{
m_buffer_tx[i] = 0x88888888;
m_buffer_tx[i+1] = caclChannelValue(128);
@electronut
electronut / main3.c
Created August 18, 2017 07:17
I2S data
#define NLEDS 16
#define RESET_BITS 6
#define I2S_BUFFER_SIZE 3*NLEDS + RESET_BITS
static uint32_t m_buffer_tx[I2S_BUFFER_SIZE];
static volatile int nled = 1;
@electronut
electronut / main2.c
Created August 18, 2017 07:15
I2S data handler
// This is the I2S data handler - all data exchange related to the I2S transfers
// is done here.
static void data_handler(uint32_t const * p_data_received,
uint32_t * p_data_to_send,
uint16_t number_of_words)
{
// Non-NULL value in 'p_data_to_send' indicates that the driver needs
// a new portion of data to send.
if (p_data_to_send != NULL)
{
@electronut
electronut / main1.c
Created August 18, 2017 07:13
I2S setup
nrf_drv_i2s_config_t config = NRF_DRV_I2S_DEFAULT_CONFIG;
config.sdin_pin = I2S_SDIN_PIN;
config.sdout_pin = I2S_SDOUT_PIN;
config.mck_setup = NRF_I2S_MCK_32MDIV10; ///< 32 MHz / 10 = 3.2 MHz.
config.ratio = NRF_I2S_RATIO_32X; ///< LRCK = MCK / 32.
config.channels = NRF_I2S_CHANNELS_STEREO;
err_code = nrf_drv_i2s_init(&config, data_handler);
APP_ERROR_CHECK(err_code);
@electronut
electronut / bluey-beacon-3.py
Created July 9, 2017 06:11
bluey-beacon - parse sensor data
# constant
pow_16 = 65536.0
# decode temperature
def decodeT(temp_val):
return ((temp_val / pow_16) * 165 - 40)
# decode humidity
def decodeH(humid_val):
return ((humid_val / pow_16) * 100)