Skip to content

Instantly share code, notes, and snippets.

View 0xc0170's full-sized avatar

Martin Kojtal 0xc0170

View GitHub Profile
@0xc0170
0xc0170 / main.cpp
Created May 13, 2015 10:45
I2c - mma7760 test asynch
#include <stdio.h>
#include "mbed.h"
#define MMA7660_ADDRESS 0x98
volatile int gevent;
volatile bool done;
volatile const char * why;
@0xc0170
0xc0170 / gist:e8cc0596a7f99e8c2a61
Last active August 29, 2015 14:14
Rust - allocate space for C object

C library - gpio_lib. Higher layer allocates objects, usually ObjC or c++. gpio_type is target specific, so each MCU has different definition for gpio_type.

void gpio_write(gpio_type *object, int32_t pin);

I want to write abstraction of Gpio object n Rust, using C library calls. Therefore need something like opaque pointer type, which will be known at the run time (currently just set to 4 bytes). This targets embedded devices, therefore no std, no libc. I don't want to redefine gpio_type for each target in rust (copy the C declaration for each target), looking for something to just allocate memory for the object.

pub enum gpio_type {}