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 "mctrl.h"
#include "rcount.h" #include "rcount.h"
#include "rs485.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; uint16_t address = 0x0000;
int16_t calib_offset = 0x0000; int16_t calib_offset = 0x0000;
@@ -38,11 +33,6 @@ uint8_t eeprom_read_c(uint16_t address) {
return EEDR; 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() { void initialSetup() {
wdt_disable(); wdt_disable();
if (eeprom_read_c(CONF_ADDR_OKAY) == CONF_CONST_OKAY) { if (eeprom_read_c(CONF_ADDR_OKAY) == CONF_CONST_OKAY) {

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" #include "mctrl.h"
// Motor driver steps definition. Reverse for direction change. // Motor driver steps definition. Reverse for direction change.
@@ -97,7 +106,7 @@ ISR(TIMER1_COMPA_vect) {
return; return;
} // if sts_flag_pwrdwn, STOP! } // if sts_flag_pwrdwn, STOP!
if (steps_since_home > 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 // home missing error. Wheel probably stuck or power fail
sts_flag_noHome = 1; sts_flag_noHome = 1;
failSafe(); failSafe();
@@ -124,24 +133,24 @@ ISR(TIMER1_COMPA_vect) {
absolute_pos--; absolute_pos--;
} else { // when no failsafe is triggered and homing is done } else { // when no failsafe is triggered and homing is done
// calculate target position // calculate target position
uint16_t target_pos = (target_flap * STEPS_PRE_FLAP) + rel_offset; uint16_t target_pos = (target_flap * STEPS_PER_FLAP) + rel_offset;
if (target_pos >= STEPS_PRE_REV) { if (target_pos >= STEPS_PER_REV) {
target_pos -= STEPS_PRE_REV; target_pos -= STEPS_PER_REV;
} }
if (absolute_pos != target_pos) { if (absolute_pos != target_pos) {
// if target position is not reached, move motor // if target position is not reached, move motor
ticksSinceMove = 0; ticksSinceMove = 0;
mctrl_step(); mctrl_step();
absolute_pos++; absolute_pos++;
if (absolute_pos >= STEPS_PRE_REV) { if (absolute_pos >= STEPS_PER_REV) {
absolute_pos -= STEPS_PRE_REV; absolute_pos -= STEPS_PER_REV;
} }
// detect home position // detect home position
if ((PIND & (1 << PD3)) == 0) { if ((PIND & (1 << PD3)) == 0) {
if (lastSens == 0) { if (lastSens == 0) {
// new home transition // new home transition
int16_t errorDelta = 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); : absolute_pos);
sts_flag_errorTooBig = sts_flag_errorTooBig =
(errorDelta > 30) || (errorDelta < -30) ? 1 : 0; (errorDelta > 30) || (errorDelta < -30) ? 1 : 0;
@@ -208,11 +217,11 @@ void mctrl_set(uint8_t flap, uint8_t fullRotation) {
if (fullRotation == 0) { if (fullRotation == 0) {
target_flap = flap; target_flap = flap;
// if (absolute_pos < STEPS_ADJ) { // if (absolute_pos < STEPS_ADJ) {
// absolute_pos += STEPS_PRE_REV; // absolute_pos += STEPS_PER_REV;
// } // }
// absolute_pos -= STEPS_ADJ; // absolute_pos -= STEPS_ADJ;
} else { } 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; afterRotation = flap;
} }
} }

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 #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_PER_REV 2025
#define STEPS_PRE_FLAP 45 #define STEPS_PER_FLAP 45
#define STEPS_ADJ 0 // added per flap to compensate for motor power down #define STEPS_ADJ 0 // added per flap to compensate for motor power down
#define AMOUNTFLAPS 45 #define AMOUNTFLAPS 45
#define ERROR_DATASETS 8 #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 #ifdef __cplusplus
extern "C" { extern "C" {
#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" #include "rcount.h"
uint8_t rc_eeprom_write_c(uint16_t address, uint8_t data) { uint8_t rc_eeprom_write_c(uint16_t address, uint8_t data) {

View File

@@ -1,5 +1,12 @@
#include <avr/io.h> /* Copyright (C) 2025 Dennis Gunia - All Rights Reserved
#include <avr/interrupt.h> * 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 #ifdef __cplusplus
extern "C" { extern "C" {
@@ -10,4 +17,3 @@ void rc_tick();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif // __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" #include "rs485.h"
void rs485_init() { 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 #pragma once
//#define F_CPU 16000000UL //#define F_CPU 16000000UL
#define UART_BAUD 19200 #define UART_BAUD 19200
@@ -6,8 +15,7 @@
#define SFBUS_SOF_BYTE '+' #define SFBUS_SOF_BYTE '+'
#define SFBUS_EOF_BYTE '$' #define SFBUS_EOF_BYTE '$'
#include <avr/io.h>
#include <avr/interrupt.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {