updated mains macros

This commit is contained in:
hugo LAMY
2025-03-06 10:26:39 +01:00
parent 3271fbf96d
commit 4a9fe6cd95
6 changed files with 254 additions and 242 deletions

View File

@@ -1,61 +1,3 @@
// #include <avr/io.h>
// // #define FIRST_LETTER_IMPL(x) #x[0]
// // #define FIRST_LETTER(x) FIRST_LETTER_IMPL(x)
// // #define PORT_LETTER(PIN) FIRST_LETTER(PIN)
// // global registers
// #define SET(register, bit) register |= 1 << bit
// #define CLEAR(register, bit) register &= ~(1 << bit)
// #define TEST(register, bit) register & 1 << bit
// #define TOGGLE(register, bit) register ^= 1 << bit
// // actions on ports
// #define TEST_PIN(port, bit) TEST(PIN ## port, bit)
// #define TOGGLE_PIN(port, bit) SET(PIN ## port, bit)
// #define MODE_INPUT(port, bit) CLEAR(DDR ## port, bit)
// #define MODE_OUTPUT(port, bit) SET(DDR ## port, bit)
// #define IS_PIN_SET(port, bit) (TEST_PIN(port, bit)) == 0
// #define IS_PIN_CLEAR(port, bit) (TEST_PIN(port, bit)) == 1
// #define TURN_ON(_PORT, BIT) SET(PORT ## _PORT, BIT)
// #define TURN_OFF(_PORT, BIT) CLEAR(PORT ## _PORT, BIT)
// // LEDs
// #define TURN_ON_LED(bit) SET(PORTB, bit)
// #define TURN_OFF_LED(bit) CLEAR(PORTB, bit)
// #define TOGGLE_LED(led) TOGGLE_PIN(B, led)
// // ELEMENTS
// #define D1 0
// #define D2 1
// #define D3 2
// #define D4 4
// #define SW1 2
// #define SW2 4
// // TIME
// #define PRESCALE_VALUE 1024
// #if (PRESCALE_VALUE == 1)
// #define PRESCALE_SET (1 << CS10)
// #elif (PRESCALE_VALUE == 8)
// #define PRESCALE_SET (1 << CS11)
// #elif (PRESCALE_VALUE == 64)
// #define PRESCALE_SET (1 << CS10) | (1 << CS11)
// #elif (PRESCALE_VALUE == 256)
// #define PRESCALE_SET (1 << CS12)
// #elif (PRESCALE_VALUE == 1024)
// #define PRESCALE_SET (1 << CS10) | (1 << CS12)
// #endif
// #define TIME_MS(ms) (((F_CPU / PRESCALE_VALUE) * ms) / 1000)
// int main() {
// MODE_OUTPUT(B, D2);
// TURN_ON(B, D2);
// }
//////////////////////////////////////////////
#include <stdio.h>
#include <avr/io.h>
// stringify
@@ -87,6 +29,8 @@
#define MODE_INPUT(elem) CLEAR(CONCAT(DDR, GET_PORT(elem)), GET_BIT(elem))
#define TOGGLE_PIN(elem) SET(CONCAT(PIN, GET_PORT(elem)), GET_BIT(elem))
#define TEST_PIN(elem) (TEST(CONCAT(PIN, GET_PORT(elem)), GET_BIT(elem)))
#define IS_PIN_SET(elem) (TEST_PIN(elem) == 0)
#define IS_PIN_CLEAR(elem) (TEST_PIN(elem) == 1)
// bits
#define D1 0
@@ -104,6 +48,7 @@
#define BUTTON1 (D, SW1)
#define BUTTON2 (D, SW2)
// END MACROS
int main()
{