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 / 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";
cmcmanis@chuck-desktop:usb_cdcacm$ make
cdcacm.c:123:2: error: unknown field 'extralen' specified in initializer
.extralen = sizeof(cdcacm_functional_descriptors)
^
In file included from /home/cmcmanis/src/kuldeep-loc3/include/libopencm3/usb/usbd.h:42:0,
from cdcacm.c:23:
cdcacm.c: In function 'cdcacm_set_config':
/home/cmcmanis/src/kuldeep-loc3/include/libopencm3/usb/usbstd.h:72:30: warning: passing argument 2 of 'usbd_register_control_callback' makes pointer from integer without a cast
#define USB_REQ_TYPE_CLASS 0x20
^
cmcmanis@chuck-desktop:src$ git clone https://github.com/kuldeepdhaka/libopencm3 kuldeep-loc3
Cloning into 'kuldeep-loc3'...
remote: Counting objects: 19583, done.
remote: Total 19583 (delta 0), reused 0 (delta 0), pack-reused 19582
Receiving objects: 100% (19583/19583), 5.61 MiB | 3.20 MiB/s, done.
Resolving deltas: 100% (11104/11104), done.
Checking connectivity... done.
cmcmanis@chuck-desktop:src$ cd kuldeep-loc3/
cmcmanis@chuck-desktop:kuldeep-loc3$ git checkout --track -b origin/usb-rewrite
Branch origin/usb-rewrite set up to track local branch master.