Skip to content

Instantly share code, notes, and snippets.

View martinribelotta's full-sized avatar
🐒
coding like a monkey

Martin Ribelotta martinribelotta

🐒
coding like a monkey
View GitHub Profile
#ifndef _SAPI_GPIO_H_
#define _SAPI_GPIO_H_
#include "sapi_datatypes.h"
#include "sapi_peripheral_map.h"
/* @question: Bitfield o valores unicos?
* Bitfield permite formar configuraciones no excluyentes que pueden
* tener sentido en muchas arquitecturas:
* GPIO_PULLUP | GPIP_PULLDOWN | GPIO_INPUT <- modo repeater en lpc43xx
#define DECL_STRING(name, value) \
char name##_strBuffer[sizeof(value)]; \
String_t name = StringNewFromC(value, name##_strBuffer)
DECL_STRING(a, "Hola mundo");
/*
char a_strBuffer[sizeof("Hola mundo")]; \
String_t a = StringNewFromC("Hola mundo", a_strBuffer)
*/
@martinribelotta
martinribelotta / Makefile
Created March 13, 2017 01:34
Silab hack updated
# Esto crea los defines traductores
silab_hack_head.h: silab_hack.txt
sed 's/^\(.*\)/#define silab_\1 \1/' $< > $@
# esto crea los undef para que no se pisen los codigos
silab_hack_tail.h: silab_hack.txt
sed 's/^\(.*\)/#undef silab_\1 \1/' $< > $@
# definir que silab_hack.h depende de *head.h y *tail.h para que se construyan automaticamente
@martinribelotta
martinribelotta / generate-bundle.sh
Last active August 29, 2017 21:31
MSYS2 bundled generation
PACKAGES="coreutils git bash"
FILTERED="'/usr/share' perl terminfo"
_F_CMD=$(for f in $FILTERED; do echo -n "grep -v -F $f | "; done)
F_CMD=${_F_CMD::-2}
D_CMD=$(pacman -Q -l $(for p in $PACKAGES; do pactree.exe -lu $p; done)|cut -d ' ' -f 2|sort -u | eval $F_CMD )
for f in $D_CMD
do
test -f $f && cp -v $f tmp$f;
test -d $f && mkdir -vp tmp$f
done
@martinribelotta
martinribelotta / armv7m_irq_svd_to_c.py
Last active October 2, 2017 19:56
Create ARMv7M vendor interrupt table from SVD description file
import re
import sys
if len(sys.argv) < 1:
print("Usage: {} <svdfile.svd>".format(sys.argv[0]))
regex = r"<interrupt>\s*<name>(\S+)<\/name>\s*<value>(\S+)<\/value>\s*<\/interrupt>"
def intname(name): return "0" if not name else "{}_IRQHandler".format(name)
def declname(name): return "void {} __attribute__((weak));".format(intname(name))
Copyright <year>, <author, authors>
<author> : <author url or mail>
<author> : <author url or mail>
<author> : <author url or mail>
This file is part of CIAA Hardware.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
@martinribelotta
martinribelotta / example.c
Created February 16, 2018 22:14
Static freeRTOS task creation macros
#include "staticTaskFreeRTOS.h"
TASK_DECL(task, configMINIMAL_STACK_SIZE) {
while(1) {
// DO anything
taskYIELD();
}
}
int main(void)
#include <programa.h>
using namespace sapi;
struct {
DigitalIn button;
DigitalOut led;
} io[] = {
{ { TEC2 }, { LED1 } },
{ { TEC3 }, { LED2 } },
interface ftdi
ftdi_device_desc "Dual RS232-HS"
ftdi_vid_pid 0x0403 0x6010
ftdi_channel 0
ftdi_layout_init 0x0708 0xFFFB
ftdi_layout_signal nTRST -data 0x0100
ftdi_layout_signal nSRST -data 0x0200
transport select jtag
adapter_khz 2000
@martinribelotta
martinribelotta / sapi_spi.c
Created November 21, 2018 19:35
sAPI SPI shift
// Add this to libs/sapi/sapi_v0.5.2/soc/peripherals/src/sapi_spi.c
void spiShiftBlock( spiMap_t spi, const uint8_t *in, uint8_t *out, uint32_t count)
{
Chip_SSP_DATA_SETUP_T xferConfig;
uint8_t out;
xferConfig.tx_data = &in;
xferConfig.tx_cnt = 0;
xferConfig.rx_data = &out;
xferConfig.rx_cnt = 0;