Skip to content

Instantly share code, notes, and snippets.

View sp5wwp's full-sized avatar

Wojciech Kaczmarski sp5wwp

View GitHub Profile
@sp5wwp
sp5wwp / zmq-sub.c
Last active May 19, 2024 18:07
ZeroMQ baseband subscriber
/*
to pass IQ baseband samples to SX1255 over I2S, run this:
./zmq-sub | aplay -t raw -f S32_LE -r 192000 -c 2 --device="hw:0,0"
note: you need to enable I2S overlay (acting as a slave)
this one works good: https://github.com/AkiyukiOkayasu/RaspberryPi_I2S_Slave
note: setting the rate to 192k isn't really effective, the actual rate is 125k (governed by the I2S master - SX1255)
*/
#include <stdio.h>
@sp5wwp
sp5wwp / zmq-pub.c
Last active May 19, 2024 18:07
ZeroMQ baseband publisher
/*
to source IQ baseband samples from SX1255 over I2S, run this:
arecord -t raw -f S32_LE -r 192000 -c 2 --device="hw:0,1" | ./zmq-pub
note: you need to enable I2S overlay (acting as a slave)
this one works good: https://github.com/AkiyukiOkayasu/RaspberryPi_I2S_Slave
note: setting the rate to 192k isn't really effective, the actual rate is 125k (governed by the I2S master - SX1255)
*/
#include <stdio.h>
@sp5wwp
sp5wwp / sx1255-spi.c
Last active May 19, 2024 17:34
SX1255 sample config using a RPi
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <math.h>
#include <sys/ioctl.h>
#include <linux/spi/spidev.h>
@sp5wwp
sp5wwp / HX8353_MD3x0.cpp
Last active April 15, 2024 10:31
TYT MD-380 screen flip
for(uint8_t y = startRow; y < endRow; y++)
{
for(uint8_t x = 0; x < SCREEN_WIDTH; x++)
{
if(y<SCREEN_HEIGHT/2)
{
size_t pos1 = x + y * SCREEN_WIDTH;
size_t pos2 = x + (SCREEN_HEIGHT-1-y) * SCREEN_WIDTH;
uint16_t tmp = frameBuffer[pos1];
frameBuffer[pos1] = __builtin_bswap16(frameBuffer[pos2]);
@sp5wwp
sp5wwp / tbgen.sh
Last active July 6, 2023 09:43
GHDL/VHDL testbench generator
#!/bin/bash
if [ "$#" -lt 1 ]; then
echo "Not enough parameters."
exit
fi
mkdir $1
cd $1
@sp5wwp
sp5wwp / AT86RF215_funcs.c
Last active May 19, 2023 11:46
A bunch of functions for AT86RF215 control
void AT86_Write(const uint16_t addr, const uint8_t val)
{
uint8_t tx[3]={(addr>>8)|(1<<7), addr&0xFF, val}; //write enable
GPIOA->BSRR=(1<<(4+16));
HAL_SPI_Transmit(&hspi1, tx, 3, 1);
GPIOA->BSRR=(1<<4);
HAL_Delay(2);
}
@sp5wwp
sp5wwp / wm8960_dac_init.c
Created December 13, 2022 14:55
WM8960 slave DAC init
delay_ms(250);
WM8960_Write(0x0F, 0x1FF); delay_ms(250); //reset
WM8960_Write(0x34, 0x018); //PLL prescale=2
WM8960_Write(0x04, 0x3B1); //clocking
//WM8960_Write(0x07, (1<<1)); //16-bit, I2S format
WM8960_Write(0x07, (1<<0)); //16-bit, left justified MSB first format
@sp5wwp
sp5wwp / i2s_sample.vhdl
Created December 13, 2022 14:50
I2S sample source - 1kHz sinewave
--I2S sample source - 1kHz sinewave
--8kHz, 16-bit, left-aligned, MSB first
--clk - 12MHz input clock
--i2s_clk - 400kHz main clock
--lr_clk - 8kHz channel clock
--outp - data output
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
@sp5wwp
sp5wwp / interpolate.c
Created November 16, 2022 15:23
24->48kSa/s interpolator
/*
* M17 baseband interpolator
*
* Wojciech Kaczmarski SP5WWP
* M17 Project, Nov 2022
*/
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% root-Nyquist (M) filter design %
% Source: %
% https://my.ece.utah.edu/~farhang/Nyquist_M_r1.pdf %
% Edited by Wojciech SP5WWP to work with rcosdesign() %
% %
% parameters: %
% N: filter order (filter length = N+1) %
% M: number of samples per symbol period %
% alpha: rolloff factor (range 0 to 1) %