Skip to content

Instantly share code, notes, and snippets.

@aykevl
aykevl / rotary.cpp
Created October 23, 2022 15:14
Rotary encoder example
#include <Arduino.h>
// Source:
// https://web.archive.org/web/20160815200234/https://www.circuitsathome.com/mcu/programming/reading-rotary-encoder-on-arduino
const uint8_t ROTARY_PIN_A = 1; // TX
const uint8_t ROTARY_PIN_B = 3; // RX
int8_t rotaryValue = 0;
@aykevl
aykevl / sizecheck.sh
Last active December 4, 2021 13:49
Size comparison for TinyGo
#!/bin/sh
# Note: use this script like so:
# git checkout dev
# ./sizecheck.sh > size0.txt
# git checkout some-feature-branch
# ./sizecheck.sh > size1.txt
# sizediff size0.txt size1.txt
for t in testdata/*.go; do echo host $t; tinygo build -o test.elf -size=short -no-debug $t; md5sum test.elf; done
@aykevl
aykevl / main.go
Created May 26, 2020 12:30
Querying static WinRT methods using Go
package main
import (
"unsafe"
"syscall"
"github.com/go-ole/go-ole"
)
type IBluetoothAdapterStatics struct {
// This is a small example (and test) how to use tilegraphics. It displays a
// small yellow square on a black background that bounces to both sides of the display.
package main
import (
"image/color"
"time"
"github.com/aykevl/go-smartwatch"
"github.com/aykevl/tilegraphics"
@aykevl
aykevl / print.go
Created August 31, 2018 18:24
Attempt to print floats. Turns out this is *really* difficult. This is my attempt so far: it isn't entirely correct.
import "unsafe"
func printfloat32(f float32) {
// Here be dragons.
// Correctly printing floats turns out to be really, really difficult (there
// have been multiple research papers on the topic). Instead of aiming to be
// exact, I've tried to print something that isn't wrong in at least most
// cases (hopefully) and doesn't look too bad. Also, I want this to be
// really small.
// TODO: make this smaller and/or more precise. Also, print some values like
@aykevl
aykevl / fire.py
Last active January 29, 2024 17:17
FastLED animations for MicroPython, see: https://forum.micropython.org/viewtopic.php?f=15&t=3749
import machine
import pixels
import array
import urandom
import time
# Source:
# https://github.com/FastLED/FastLED/blob/master/examples/Fire2012WithPalette/Fire2012WithPalette.ino
heatColors = array.array('L', [0x000000,
#include <stdio.h>
__attribute__((used))
int bar() {
printf("bar\n");
return 42;
}
__attribute__((noinline,naked))
diff --git a/ports/nrf/hal/hal_uart.c b/ports/nrf/hal/hal_uart.c
index 39590272b..583a8761d 100644
--- a/ports/nrf/hal/hal_uart.c
+++ b/ports/nrf/hal/hal_uart.c
@@ -122,7 +122,7 @@ void hal_uart_init(NRF_UART_Type * p_instance, hal_uart_init_t const * p_uart_in
if (p_uart_init->flow_control) {
hal_gpio_cfg_pin(p_uart_init->rts_pin->port, p_uart_init->rts_pin->pin, HAL_GPIO_MODE_OUTPUT, HAL_GPIO_PULL_DISABLED);
- hal_gpio_cfg_pin(p_uart_init->cts_pin->port, p_uart_init->cts_pin->pin, HAL_GPIO_MODE_INPUT, HAL_GPIO_PULL_DISABLED);
+ hal_gpio_cfg_pin(p_uart_init->cts_pin->port, p_uart_init->cts_pin->pin, HAL_GPIO_MODE_INPUT, HAL_GPIO_PULL_DOWN);
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2018 Glenn Ruben Bakke
*
* 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
diff --git a/ports/nrf/bluetooth_conf.h b/ports/nrf/bluetooth_conf.h
index 6a3cbdc83..9e649c940 100644
--- a/ports/nrf/bluetooth_conf.h
+++ b/ports/nrf/bluetooth_conf.h
@@ -6,7 +6,7 @@
#if (BLUETOOTH_SD == 110)
#define MICROPY_PY_BLE (1)
-#define MICROPY_PY_BLE_NUS (0)
+#define MICROPY_PY_BLE_NUS (1)