DIY Framework 328P AVR

Hi :slight_smile:

Last 8 months I developed an AVR framework for the Atmega 328p (for your Arduino uno board).

(my framework is easily adaptable for other uC too…)

This is work in progress project, I want to finish Gyro, Gps, and pwm input class for Drone application, but actually the framework is 100% ok for multiple electronics projects.

It contain this class:

#include "../framework/Timer.h"
#include "../framework/Button.h"
#include "../framework/Led.h"
#include "../framework/LedDigit.h"
#include "../framework/LedMatrix8x8.h"
#include "../framework/LedMatrix64x64.h"
#include "../framework/Iteration.h"
#include "../framework/Random.h"
#include "../framework/Interrupt.h"
#include "../framework/Potentiometer.h"
#include "../framework/Math.h"
#include "../framework/Buzzer.h"
#include "../framework/Memory.h"
#include "../framework/Servo.h"

Class contain this fonction:

Timer.h:

Timer (const uint32_t DURATION);
static void start();
static void pause (const uint32_t DURATION);
void state();
void set (const uint32_t DURATION);
void reset();
static void stop();

Button.h:

Button (uint8_t PIN, bool PULL_UP_INTERNAL);
void state();

Led.h:

Led (const uint8_t PIN);
void toggle();
void on();
void off();

LedDigit.h:

LedDigit (const uint8_t PIN_SS, const uint8_t PIN_MOSI, const uint8_t PIN_SCK, const uint8_t DEVICE);
void scanLimit (const uint8_t LIMIT);
void brightness (const uint8_t BRIGHTNESS);
void digit (const uint8_t DIGIT, const bool COMMA, const uint8_t POSITION);
void number (const int32_t NUMBER, const uint8_t POSITION_MIN, const uint8_t POSITION_MAX, const uint8_t DIGIT_AFTER_COMMA, const bool SIDE);
void character (const char *CHARACTER, const uint8_t ADDRESS);
void word (const char *CHARACTER1, const char *CHARACTER2, const char *CHARACTER3, const char *CHARACTER4, const char *CHARACTER5, const char *CHARACTER6, const char *CHARACTER7, const char *CHARACTER8);
void draw (const uint8_t DRAW, const uint8_t POSITION);
void clearDigit (const uint8_t POSITION);
void clearDevice();

LedMatrix8x8.h:

LedMatrix8x8 (const uint8_t PIN_SS, const uint8_t PIN_MOSI, const uint8_t PIN_SCK, const uint8_t DEVICE);
void scanLimit (const uint8_t LIMIT);
void brightness (const uint8_t BRIGHTNESS);
void dot (const uint8_t X, const uint8_t Y);
void draw (const uint8_t DRAW, const uint8_t Y);
void clearY (const uint8_t Y);
void clearDevice();

LedMatrix64x64.h:

LedMatrix64x64 (const uint8_t PIN_SS, const uint8_t PIN_MOSI1, const uint8_t PIN_MOSI2, const uint8_t PIN_MOSI3, const uint8_t PIN_MOSI4, const uint8_t PIN_MOSI5, const uint8_t PIN_MOSI6, const uint8_t PIN_MOSI7, const uint8_t PIN_MOSI8, const uint8_t PIN_SCK);
void scanLimit (const uint8_t LIMIT);
void brightness (const uint8_t BRIGHTNESS);
void dot (const uint8_t X, const uint8_t Y);
void draw (const uint64_t DRAW, const uint8_t Y);
void clearY (const uint8_t Y);
void clearDevice();

Iteration.h:

Iteration (const int32_t START, const int32_t MIN, const int32_t MAX, const bool LOOP);
void increment (const int32_t INCREMENT);
void decrement (const int32_t DECREMENT);
void set (const int32_t VALUE);
void reset();
void min (const int32_t MIN);
void max (const int32_t MAX);
void loop (const bool LOOP);

Random.h:

static void seed (const uint8_t PIN);
static bool boolean();
static int32_t integer (const int32_t MIN, const int32_t MAX);

Interrupt.h:

Interrupt (const uint8_t PIN);
void start (void functionCall(), const bool FALLING);
void stop();

Potentiometer.h:

Potentiometer (const uint8_t PIN);
void state();
int32_t curve (const uint16_t POTENTIOMETER_START, const uint16_t POTENTIOMETER_END, const int32_t INTERPOLATION_START, const int32_t INTERPOLATION_END, const int8_t CURVE);
int32_t smooth (const uint16_t POTENTIOMETER_START, const uint16_t POTENTIOMETER_END, const int32_t INTERPOLATION_START, const int32_t INTERPOLATION_END, const int8_t CURVE);

Math.h:

static int32_t curve (const int32_t POSITION_START, const int32_t POSITION_CURRENT, const int32_t POSITION_END, const int32_t INTERPOLATION_START, const int32_t INTERPOLATION_END, const uint8_t CURVE);
static int32_t smooth (const int32_t POSITION_START, const int32_t POSITION_CURRENT, const int32_t POSITION_END, const int32_t INTERPOLATION_START, const int32_t INTERPOLATION_END, const uint8_t CURVE);

Buzzer.h:

static void start (const uint8_t PIN);
static void play (const uint16_t FREQUENCY, const uint32_t DURATION);
static void playInfinite (const uint16_t FREQUENCY);
static void modulate (const uint16_t FREQUENCY);
static void key (const uint16_t FREQUENCY, const uint32_t DURATION);
static void playMelody();
static void stop();

Memory.h:

static void write8Bit (const uint16_t ADDRESS, const uint8_t DATA);
static void write16Bit (const uint16_t ADDRESS1, const uint16_t ADDRESS2, const uint16_t DATA);
static void write32Bit (const uint16_t ADDRESS1, const uint16_t ADDRESS2, const uint16_t ADDRESS3, const uint16_t ADDRESS4, uint32_t DATA);
static uint8_t read8Bit (const uint16_t ADDRESS);
static uint16_t read16Bit (const uint16_t ADDRESS1, const uint16_t ADDRESS2);
static uint32_t read32Bit (const uint16_t ADDRESS1, const uint16_t ADDRESS2, const uint16_t ADDRESS3, const uint16_t ADDRESS4);
static void erase8Bit (const uint16_t ADDRESS);
static void erase16Bit (const uint16_t ADDRESS1, const uint16_t ADDRESS2);
static void erase32Bit (const uint16_t ADDRESS1, const uint16_t ADDRESS2, const uint16_t ADDRESS3, const uint16_t ADDRESS4);
static void eraseAll();

Servo.h:

Servo (const uint8_t PIN, const uint16_t PULSE_MIN, const uint16_t PULSE_MAX);
static void start (const uint16_t FREQUENCY);
void min (const uint16_t PULSE_MIN);
void center (const uint16_t PULSE_CENTER);
void max (const uint16_t PULSE_MAX);
void pulse (const uint16_t PULSE);
void move10Bit (const uint16_t BIT);
void movePercentage (const uint8_t PERCENTAGE);
void moveMin();
void moveCenter();
void moveMax();

BLINK (.INO) BENCHMARK :smiley:

AVR : 158 bytes / (691 ms → 1000000 pin toggling)

#include "avr/io.h"
#include "util/delay.h"

using namespace std;

int main()
{
	DDRD |= 0b00000001;
	
	while (true)
	{
		PIND = 0b00000001;
		_delay_ms (1000);
	}
	
	return 0;
}

My AVR framework : 378 bytes / (753 ms → 1000000 pin toggling)

#include "../framework/Led.h"
#include "../framework/Timer.h"

using namespace std;

int main()
{
	Led led = Led (1);
	
	while (true)
	{
		led.toggle();
		Timer::pause (1000);
	}
	
	return 0;
}

Arduino framework : 1076 bytes / (4550 ms → 1000000 pin toggling)

void setup()
{
	pinMode (0, OUTPUT);
}

void loop()
{
	digitalWrite (0, HIGH);
	delay (1000);
	digitalWrite (0, LOW);
	delay (1000);
}

Benchmarking blink is really basic, but my all framework as verified like this, optimised and tested line per line, logical bloc per logical bloc, fonction per fonction.

If you are interested, contact me for download :slight_smile:

Or develop your own framework :slight_smile: