chore: debloat (remove platformio), onewire improvements

Squashed commit of the following:

commit 5f16309f629b9928d2134b85ae64af69bc3ebbcd
Author: kuwoyuki <kuwoyuki@cock.li>
Date:   Sun Nov 24 22:55:15 2024 +0600

    fix: Makefile, improve onewire retries

commit 55496a3bda941b52ff349dc75c9c06eb5a37c07d
Author: kuwoyuki <kuwoyuki@cock.li>
Date:   Mon Nov 18 00:41:18 2024 +0600

    fix: make onewire validity less strict

commit 3428a9bc9792508972ce3e7e4e35a64f047bca10
Author: kuwoyuki <kuwoyuki@cock.li>
Date:   Sun Nov 17 23:57:55 2024 +0600

    chore: rm bins

commit 1594e5ed430522b15466c8afa62ff7fb1b28947c
Author: kuwoyuki <kuwoyuki@cock.li>
Date:   Sun Nov 17 23:32:01 2024 +0600

    chore: unplatformiofy
This commit is contained in:
2024-11-24 22:56:05 +06:00
parent 2a7aa8aea3
commit 8adc726b0b
74 changed files with 141 additions and 195 deletions

View File

@@ -1,39 +0,0 @@
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 usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.
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

17
include/funconfig.h Normal file
View File

@@ -0,0 +1,17 @@
#ifndef _FUNCONFIG_H
#define _FUNCONFIG_H
#define CH32V20x 1
#define FUNCONF_USE_HSI 0 // Use HSI Internal Oscillator
#define FUNCONF_USE_HSE 1 // Use External Oscillator
#define FUNCONF_SYSTEM_CORE_CLOCK 144000000 // System Core Clock in Hz
#define FUNCONF_USE_DEBUGPRINTF 0
#define FUNCONF_USE_UARTPRINTF 0
#define FUNCONF_UART_PRINTF_BAUD \
115200 // Only used if FUNCONF_USE_UARTPRINTF is set.
#define FUNCONF_USE_CLK_SEC 1
#define FUNCONF_SYSTICK_USE_HCLK 1
#define FUNCONF_DEBUG 1
#endif

119
include/onewire.h Normal file
View File

@@ -0,0 +1,119 @@
#ifndef CH32V003_ONEWIRE_H
#define CH32V003_ONEWIRE_H
#include <stdbool.h>
#include <stdint.h>
#include "ch32v003fun.h"
// GPIO Direct Access Definitions
#ifndef OneWire_Direct_GPIO_h
#define OneWire_Direct_GPIO_h
static inline __attribute__((always_inline)) uint8_t directRead() {
return (GPIOB->INDR & (1 << 9)) ? 1 : 0;
}
static inline void directModeInput() {
GPIOB->CFGHR &= ~(0xF << (4 * (9 - 8)));
GPIOB->CFGHR |= (GPIO_CNF_IN_FLOATING << (4 * (9 - 8)));
}
static inline void directModeOutput() {
GPIOB->CFGHR &= ~(0xF << (4 * (9 - 8)));
GPIOB->CFGHR |= ((GPIO_Speed_50MHz | GPIO_CNF_OUT_PP) << (4 * (9 - 8)));
}
static inline __attribute__((always_inline)) void directWriteLow() {
GPIOB->BCR = (1 << 9);
}
static inline __attribute__((always_inline)) void directWriteHigh() {
GPIOB->BSHR = (1 << 9);
}
#define DIRECT_READ() directRead()
#define DIRECT_WRITE_LOW() directWriteLow()
#define DIRECT_WRITE_HIGH() directWriteHigh()
#define DIRECT_MODE_INPUT() directModeInput()
#define DIRECT_MODE_OUTPUT() directModeOutput()
#endif
// timing configuration
// time between line check retries
#define ONEWIRE_RESET_RETRY_TIME 2
// reset cycle
#define ONEWIRE_RESET_LOW_TIME 480
#define ONEWIRE_RESET_SAMPLE_TIME 60
#define ONEWIRE_RESET_POST_TIME 410
// write 1 bit
#define ONEWIRE_WRITE_1_LOW_TIME 6
#define ONEWIRE_WRITE_1_TOTAL_TIME 64
// write 0 bit
#define ONEWIRE_WRITE_0_LOW_TIME 80
#define ONEWIRE_WRITE_0_TOTAL_TIME 84
// read bit
#define ONEWIRE_READ_INIT_LOW_TIME 6
#define ONEWIRE_READ_SAMPLE_TIME 8
#define ONEWIRE_READ_TOTAL_TIME 64
// OneWire Function Declarations
// Initialize the OneWire bus
void OneWireBegin(void);
// Perform a 1-Wire reset cycle. Returns 1 if a device responds with a presence
// pulse
uint8_t OneWireReset(void);
// Select a device on the bus using its ROM code
void OneWireSelect(const uint8_t rom[8]);
// Skip ROM selection - addresses all devices on the bus
void OneWireSkip(void);
// Write a byte to the bus. If 'power' is true, maintain strong pullup after
// write
void OneWireWrite(uint8_t v, uint8_t power);
// Write multiple bytes to the bus
void OneWireWriteBytes(const uint8_t *buf, uint16_t count, bool power);
// Read a byte from the bus
uint8_t OneWireRead(void);
// Read multiple bytes from the bus
void OneWireReadBytes(uint8_t *buf, uint16_t count);
// Write a single bit to the bus
void OneWireWriteBit(uint8_t v);
// Read a single bit from the bus
uint8_t OneWireReadBit(void);
// Stop forcing power onto the bus
void OneWireDepower(void);
// Reset the search state
void OneWireResetSearch(void);
// Setup search to find devices of a specific family code
void OneWireTargetSearch(uint8_t family_code);
// Search for the next device on the bus
bool OneWireSearch(uint8_t *newAddr, bool search_mode);
// Calculate 8-bit CRC
uint8_t OneWireCrc8(const uint8_t *addr, uint8_t len);
// Check if received CRC matches calculated CRC
bool OneWireCheckCrc16(const uint8_t *input, uint16_t len,
const uint8_t *inverted_crc, uint16_t crc);
// Calculate 16-bit CRC
uint16_t OneWireCrc16(const uint8_t *input, uint16_t len, uint16_t crc);
#endif // CH32V003_ONEWIRE_H