Adding all files from Project 1 to start

This commit is contained in:
2026-09-10 10:15:52 +00:00
parent 2bd9fb2ba4
commit a73f7002bc
22 changed files with 786 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the convention is to give header files names that end with `.h'.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
+14
View File
@@ -0,0 +1,14 @@
#ifndef DIGITAL_IN_H
#define DIGITAL_IN_H
#include <stdint.h>
struct Digital_in {
uint8_t pin_mask;
Digital_in(uint8_t pin);
void init();
bool is_hi();
bool is_lo();
};
#endif
+15
View File
@@ -0,0 +1,15 @@
#ifndef DIGITAL_OUT_H
#define DIGITAL_OUT_H
#include<stdint.h>
struct Digital_out {
uint8_t pin_mask;
Digital_out(uint8_t pin);
void init();
void toggle();
void set_hi();
void set_lo();
};
#endif
+31
View File
@@ -0,0 +1,31 @@
#ifndef ROTARY_ENCODER_DRIVER_H
#define ROTARY_ENCODER_DRIVER_H
#include "digital_in.h"
#include "digital_out.h"
#include "timer_usec.h"
class RotaryEncoderDriver {
volatile uint8_t cycle;
volatile int16_t count;
volatile int16_t prev_count;
Digital_out led;
Digital_in eA;
Digital_in eB;
Timer_usec timer;
public:
volatile int16_t delta;
RotaryEncoderDriver();
void begin();
void update();
int position();
void update_delta();
float count_per_sec();
};
#endif
+9
View File
@@ -0,0 +1,9 @@
#ifndef TIMER_USEC_H
#define TIMER_USEC_H
#include <avr/io.h>
struct Timer_usec {
Timer_usec();
void init(uint16_t period_us);
};
#endif