Skip to content

Instantly share code, notes, and snippets.

@dagon666
dagon666 / soft_timer.h
Created October 12, 2013 15:34
software timer interface
#include <stdint.h>
// modify this to change the timer resolution
typedef uint8_t st_type;
/**
* @brief software timer callback handler type declaration
*
* @return void
*/
@dagon666
dagon666 / messages.h
Last active December 25, 2015 09:08
binary message format
#include <stdint.h>
typedef enum _e_status {
ACK = 0x00,
NACK
} e_status;
struct timer_data {
uint16_t crc16;
@dagon666
dagon666 / arduino_slip.c
Created October 12, 2013 21:27
arduino_slip demonstration
#include "pca.h"
#include "../model.h"
#include "main.h"
#include <avr/interrupt.h>
#include <util/atomic.h>
#define LED_DDRD DDRB
#define LED_PORT PORTB
#define LED_PIN PORTB0
@dagon666
dagon666 / host_slip.pl
Created October 12, 2013 21:54
SLIP communication over serial port with Arduino in Perl
#!/usr/bin/env perl
use strict;
use warnings;
$|++;
use Device::SerialPort;
use Digest::CRC qw/crc16/;
use Time::HiRes qw/usleep/;
@dagon666
dagon666 / crc16.c
Created October 13, 2013 14:55
crc16 implementation taken from the linux kernel
#include <stdint.h>
#include "crc.h"
/** CRC table for the CRC-16. The poly is 0x8005 (x^16 + x^15 + x^2 + 1) */
uint16_t const crc16_table[256] = {
0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241,
0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440,
0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40,
0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841,
0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40,
@dagon666
dagon666 / serial_init.c
Created October 13, 2013 14:57
serial port initialization routines
#define BAUD_2400 B2400
#define BAUD_4800 B4800
#define BAUD_9600 B9600
#define BAUD_38400 B38400
#define BAUD_57600 B57600
#define BAUD_115200 B115200
static int tty_attrib_conf(int fd, int speed, int parity) {
@dagon666
dagon666 / host_slip.c
Created October 13, 2013 15:19
slip binary IO in C
int main(int argc, char const *argv[]) {
g_fd = 0x00;
struct response *resp;
struct timer_data *data;
uint8_t buff[8] = {0x00};
uint16_t crc = 0x00;
if (argc <= 3) {
fprintf(stderr, "host_slip <prescaler> <ocr> <st_max>\n");
@dagon666
dagon666 / mid_converter.pl
Last active December 25, 2015 19:39
mid_converter processing loop
while (1) {
my @alsa_event = MIDI::ALSA::input();
# last event -> exit
last if ($alsa_event[0] == SND_SEQ_EVENT_PORT_UNSUBSCRIBED());
# midi event to midi score event
my @score_event = MIDI::ALSA::alsa2scoreevent( @alsa_event );
# filter out empty events
@dagon666
dagon666 / msg.h
Created October 17, 2013 18:18
music box binary messages format
struct note {
uint16_t note;
uint16_t duration;
};
struct packet {
uint16_t crc16;
unsigned char num;
struct note notes[4];
};
@dagon666
dagon666 / musicbox.c
Last active December 25, 2015 19:39
Arduino MIDI musicbox
#include "beeper.h"
#include "notes.h"
#include "serial.h"
#include "slip.h"
#include <avr/io.h>
#include <util/delay.h>
struct note {
uint16_t note;