Go Down

Topic: 328P AVR DIY Framework (Read 235 times) previous topic - next topic

sylvainmahe

Hi :)

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:
Code: [Select]
#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:
Code: [Select]
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:
Code: [Select]
Button (uint8_t PIN, bool PULL_UP_INTERNAL);
void state();


Led.h:
Code: [Select]
Led (const uint8_t PIN);
void toggle();
void on();
void off();


LedDigit.h:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
static void seed (const uint8_t PIN);
static bool boolean();
static int32_t integer (const int32_t MIN, const int32_t MAX);


Interrupt.h:
Code: [Select]
Interrupt (const uint8_t PIN);
void start (void functionCall(), const bool FALLING);
void stop();


Potentiometer.h:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
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-lol:

AVR : 158 bytes / (691 ms -> 1000000 pin toggling)
Code: [Select]
#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)
Code: [Select]
#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)
Code: [Select]
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 :)
Or develop your own framework :)

Robin2


Quote
If you are interested, contact me for download
Why not just either add it as an attachment or post a link to wherever it can be downloaded from ?

...R

sylvainmahe

Because I don't want this topic is like a supermarket, people must really want rather than beginners test and criticize without understanding.

Robin2

Because I don't want this topic is like a supermarket, people must really want rather than beginners test and criticize without understanding.
Have you ever asked yourself why supermarkets are so popular ?

...R

sylvainmahe

#4
Jul 04, 2015, 12:28 pm Last Edit: Jul 05, 2015, 12:07 pm by sylvainmahe
Ha ha :)

True, but supermarkets are so popular because they are low cost and usually bad product monsanto quality than bio local market :)

My local market is attached at this post now. ;)


Compilation/upload routine (linux) with usbasp programmer:
Code: [Select]
#!/bin/bash

while true
do
 avr-gcc main.cpp -mmcu=atmega328p -DF_CPU=16000000 -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -std=c++11 -o main.elf
 objcopy main.elf -O ihex main.hex
 avrdude -c usbasp -b 921600 -p m328p -P /dev/ttyACM0 -U flash:w:main.hex:i
 
 rm main.elf -f
 rm main.hex -f
 
 read
 clear
done

exit 0


Use:
-Os option to optimize size
-O3 option to optimize speed

Robin2

#5
Jul 04, 2015, 05:13 pm Last Edit: Jul 04, 2015, 05:19 pm by Robin2
True, but supermarkets are so popular because they are low cost and usually bad product monsanto quality than bio local market :)
This bio nonsense is just an excuse not to wash the clay off the potatoes and charge you for clay as well as potatoes.  :)


Thanks for posting your code in the supermarket.

...R

sylvainmahe

If you believe it, that's your problem.
When you have garden like me you will understand that the food is much better, taste and texture.

The Humanity eat bio-organic since 3 million years... but after conversion of bomb factories and fighting substances to fertilizers and pesticides factories, Marketing want us believe eat poison is good for health and good for earth, it also requires morons to believe their bullshit, this is the major part of the population unfortunately, like you.

Robin2

The Humanity eat bio-organic since 3 million years... but after conversion of bomb factories and fighting substances to fertilizers and pesticides factories, Marketing want us believe eat poison is good for health and good for earth, it also requires morons to believe their bullshit, this is the major part of the population unfortunately, like you.
I expressed doubts about the marketing of "organic food". I did not call you a MORON.

There is no call for personal abuse.

...R

Go Up