Add licence

This commit is contained in:
2025-01-10 15:00:00 +01:00
parent ad449188d5
commit 26e9075871
8 changed files with 114 additions and 50 deletions

View File

@@ -0,0 +1,33 @@
/* Copyright (C) 2025 Dennis Gunia - All Rights Reserved
* You may use, distribute and modify this code under the
* terms of the AGPL-3.0 license.
*
* https://www.dennisgunia.de
* https://github.com/dennis9819/splitflap_v1
*/
#include <avr/io.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdlib.h>
#include <string.h>
// I/O Pin definition
#define BUX_RX PD0
#define BUX_TX PD1
#define BUX_DIR PD2
#define SENSOR_HOME PD3
#define MOTOR_A PC0
#define MOTOR_B PC1
#define MOTOR_C PC2
#define MOTOR_D PC3
// EEPROM Addresses
#define CONF_CONST_OKAY (uint8_t)0xAA
#define CONF_ADDR_OKAY 0x0004
#define CONF_ADDR_ADDR 0x0000
#define CONF_ADDR_OFFSET 0x0002

View File

@@ -1,20 +1,15 @@
/* Copyright (C) 2025 Dennis Gunia - All Rights Reserved
* You may use, distribute and modify this code under the
* terms of the AGPL-3.0 license.
*
* https://www.dennisgunia.de
* https://github.com/dennis9819/splitflap_v1
*/
#include "global.h"
#include "mctrl.h"
#include "rcount.h"
#include "rs485.h"
#include <avr/io.h>
#include <avr/wdt.h>
#include <stdlib.h>
#include <util/delay.h>
/*
* PD0 -> BUS_RX
* PD1 -> BUS_TX
* PD2 -> BUS_DIR (0=RECV/1=SEND)
*
* PD3 -> SENSOR_IN
*
* PC0-3 -> MOTOR CTRL
*/
uint16_t address = 0x0000;
int16_t calib_offset = 0x0000;
@@ -38,11 +33,6 @@ uint8_t eeprom_read_c(uint16_t address) {
return EEDR;
}
#define CONF_CONST_OKAY (uint8_t)0xAA
#define CONF_ADDR_OKAY 0x0004
#define CONF_ADDR_ADDR 0x0000
#define CONF_ADDR_OFFSET 0x0002
void initialSetup() {
wdt_disable();
if (eeprom_read_c(CONF_ADDR_OKAY) == CONF_CONST_OKAY) {
@@ -159,4 +149,4 @@ int main() {
while (1 == 1) {
readCommand();
}
}
}

View File

@@ -1,3 +1,12 @@
/* Copyright (C) 2025 Dennis Gunia - All Rights Reserved
* You may use, distribute and modify this code under the
* terms of the AGPL-3.0 license.
*
* https://www.dennisgunia.de
* https://github.com/dennis9819/splitflap_v1
*/
#include "mctrl.h"
// Motor driver steps definition. Reverse for direction change.
@@ -97,7 +106,7 @@ ISR(TIMER1_COMPA_vect) {
return;
} // if sts_flag_pwrdwn, STOP!
if (steps_since_home >
STEPS_PRE_REV * 1.5) { // check if home is missing for too long
STEPS_PER_REV * 1.5) { // check if home is missing for too long
// home missing error. Wheel probably stuck or power fail
sts_flag_noHome = 1;
failSafe();
@@ -124,24 +133,24 @@ ISR(TIMER1_COMPA_vect) {
absolute_pos--;
} else { // when no failsafe is triggered and homing is done
// calculate target position
uint16_t target_pos = (target_flap * STEPS_PRE_FLAP) + rel_offset;
if (target_pos >= STEPS_PRE_REV) {
target_pos -= STEPS_PRE_REV;
uint16_t target_pos = (target_flap * STEPS_PER_FLAP) + rel_offset;
if (target_pos >= STEPS_PER_REV) {
target_pos -= STEPS_PER_REV;
}
if (absolute_pos != target_pos) {
// if target position is not reached, move motor
ticksSinceMove = 0;
mctrl_step();
absolute_pos++;
if (absolute_pos >= STEPS_PRE_REV) {
absolute_pos -= STEPS_PRE_REV;
if (absolute_pos >= STEPS_PER_REV) {
absolute_pos -= STEPS_PER_REV;
}
// detect home position
if ((PIND & (1 << PD3)) == 0) {
if (lastSens == 0) {
// new home transition
int16_t errorDelta =
(absolute_pos > (STEPS_PRE_REV / 2) ? absolute_pos - STEPS_PRE_REV
(absolute_pos > (STEPS_PER_REV / 2) ? absolute_pos - STEPS_PER_REV
: absolute_pos);
sts_flag_errorTooBig =
(errorDelta > 30) || (errorDelta < -30) ? 1 : 0;
@@ -208,11 +217,11 @@ void mctrl_set(uint8_t flap, uint8_t fullRotation) {
if (fullRotation == 0) {
target_flap = flap;
// if (absolute_pos < STEPS_ADJ) {
// absolute_pos += STEPS_PRE_REV;
// absolute_pos += STEPS_PER_REV;
// }
// absolute_pos -= STEPS_ADJ;
} else {
target_flap = (target_flap + (STEPS_PRE_FLAP - 1)) % STEPS_PRE_FLAP;
target_flap = (target_flap + (STEPS_PER_FLAP - 1)) % STEPS_PER_FLAP;
afterRotation = flap;
}
}
@@ -239,4 +248,4 @@ void mctrl_step() {
step_index = 0;
}
PORTC = motor_steps[step_index];
}
}

View File

@@ -1,24 +1,25 @@
/* Copyright (C) 2025 Dennis Gunia - All Rights Reserved
* You may use, distribute and modify this code under the
* terms of the AGPL-3.0 license.
*
* https://www.dennisgunia.de
* https://github.com/dennis9819/splitflap_v1
*/
#include "global.h"
#include "rcount.h"
#pragma once
#define MP_A PC0
#define MP_B PC1
#define MP_C PC2
#define MP_D PC3
#define STEPS_PRE_REV 2025
#define STEPS_PRE_FLAP 45
#define STEPS_PER_REV 2025
#define STEPS_PER_FLAP 45
#define STEPS_ADJ 0 // added per flap to compensate for motor power down
#define AMOUNTFLAPS 45
#define ERROR_DATASETS 8
#include <stdlib.h>
#include <string.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "rcount.h"
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
@@ -33,4 +34,4 @@ void mctrl_power(uint8_t state);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // __cplusplus

View File

@@ -1,3 +1,12 @@
/* Copyright (C) 2025 Dennis Gunia - All Rights Reserved
* You may use, distribute and modify this code under the
* terms of the AGPL-3.0 license.
*
* https://www.dennisgunia.de
* https://github.com/dennis9819/splitflap_v1
*/
#include "rcount.h"
uint8_t rc_eeprom_write_c(uint16_t address, uint8_t data) {

View File

@@ -1,5 +1,12 @@
#include <avr/io.h>
#include <avr/interrupt.h>
/* Copyright (C) 2025 Dennis Gunia - All Rights Reserved
* You may use, distribute and modify this code under the
* terms of the AGPL-3.0 license.
*
* https://www.dennisgunia.de
* https://github.com/dennis9819/splitflap_v1
*/
#include "global.h"
#ifdef __cplusplus
extern "C" {
@@ -10,4 +17,3 @@ void rc_tick();
#ifdef __cplusplus
}
#endif // __cplusplus

View File

@@ -1,3 +1,11 @@
/* Copyright (C) 2025 Dennis Gunia - All Rights Reserved
* You may use, distribute and modify this code under the
* terms of the AGPL-3.0 license.
*
* https://www.dennisgunia.de
* https://github.com/dennis9819/splitflap_v1
*/
#include "rs485.h"
void rs485_init() {

View File

@@ -1,3 +1,12 @@
/* Copyright (C) 2025 Dennis Gunia - All Rights Reserved
* You may use, distribute and modify this code under the
* terms of the AGPL-3.0 license.
*
* https://www.dennisgunia.de
* https://github.com/dennis9819/splitflap_v1
*/
#include "global.h"
#pragma once
//#define F_CPU 16000000UL
#define UART_BAUD 19200
@@ -6,8 +15,7 @@
#define SFBUS_SOF_BYTE '+'
#define SFBUS_EOF_BYTE '$'
#include <avr/io.h>
#include <avr/interrupt.h>
#ifdef __cplusplus
extern "C" {
@@ -24,4 +32,4 @@ void sfbus_send_frame(uint16_t address, char* payload, uint8_t length);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // __cplusplus