Skip to content

Instantly share code, notes, and snippets.

View ChuckM's full-sized avatar

Chuck McManis ChuckM

View GitHub Profile
@ChuckM
ChuckM / example.py
Created July 29, 2023 06:02
A sketch of what I'm kind of trying to implement
#
# "generic" multi-phase clock module
#
from amaranth import *
class SysClock(Elaboratable):
"""
This builds a clock divider
Input is a clock, output is a multi-phase
@ChuckM
ChuckM / i2s.py
Created October 21, 2021 06:20
i2s clock generation and shifting loop
#
# xmit_reg is a Signal(16) as are left_dr and right_dr
#
self.sync += [
mclk.eq(~mclk), # running at 1/2 the clock rate (25MHz)
# @posedge of MCLK
If(mclk == 0,
If(sticks == 15,
sticks.eq(0),
sclk.eq(~sclk),
@ChuckM
ChuckM / farewell.md
Last active June 7, 2021 18:21
On my departure (fictional)

Dear non-executive team members,

All of my options have vested, and I haven’t been offered any new ones so my earning potential here is no longer all that great. Worse, as we’ve operated and developed better understandings of the problems we face it seems less likely than ever that we’ll achieve the vision we set out to achieve. Finally, the blackout periods are having a real negative effect on my ability to diversify my wealth and avoid the high risk of this company’s success chances. Therefore I’m leaving on a “high note” while we can still plausibly call this endeavor a success, and after I’ve left will convert all my equity in this venture into other forms of wealth while not having to report it

@ChuckM
ChuckM / isr_xmit.c
Last active September 7, 2018 23:23
Transmitting characters with the interrupt sub system
#define BUF_SIZE 16
char ring_buf[BUF_SIZE];
uint8_t cur_char, nxt_char = 0;
void _write_char(char *c)
{
/* ring buffer is full, wait for isr to drain a character out of it */
while (((cur_char + 1) % BUF_SIZE) == nxt_char) ;
/* Is the USART idle? Then just write the character */
@ChuckM
ChuckM / fft.c
Last active May 30, 2018 05:32
Simple implementation of the Complex FFT in C99
double complex *
fft(double complex iq[], int bins)
{
int i, j, k;
int q;
double t;
complex double alpha, uri, ur;
complex double *foo;
/* and they must be a power of 2 */
@ChuckM
ChuckM / clock.c
Created April 30, 2018 22:13
A different clock setup feature
/*
* Easier to use clock functions
*/
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/pwr.h>
#include <libopencm3/stm32/flash.h>
#include <libopencm3/cm3/systick.h>
#include <libopencm3/cm3/nvic.h>
#include <utilloc3/stm32/clock.h>
@ChuckM
ChuckM / stmpe811-example.c
Last active September 11, 2017 23:32
STMPE811 Touch Controller example
/*
* Look at using the i2c functions in the utility library
*
* Copyright (c) 2015, Chuck McManis, all rights reserved.
*
* This example talks to the XY screen touch controller
* (its a peripheral already on the board) and prints
* the co-ordinates pressed on the serial port.
*/
@ChuckM
ChuckM / Broken SPI.c
Last active July 19, 2017 12:23
SPI Test that Doesn't work
/* makes capturing the output with a logic analyzer easier */
#define FLAG_ON gpio_set(GPIOC, GPIO2)
#define FLAG_OFF gpio_clear(GPIOC, GPIO2)
/*
* This then sets up the SPI2 port
*/
void
spi_test(void) {
rcc_periph_clock_enable(RCC_SPI1);
@ChuckM
ChuckM / i2c.c
Created March 11, 2017 01:31
i2c utility functions
/*
* Look at using the i2c functions in the library
*
* This example talks to the XY screen touch controller
* (its a peripheral already on the board) and prints
* the co-ordinates pressed on the serial port.
*/
#include <stdint.h>
#include <stdio.h>
@ChuckM
ChuckM / genfont.pl
Created August 23, 2016 06:14
Trying to pull a font out of a bitmap
#!/usr/bin/env perl
use strict;
use warnings;
use Graphics::Magick;
use Data::Dumper;
use Getopt::Long;
my $code;
my $font = "reg-bold-italic-full.png";