Skip to content
Snippets Groups Projects
Commit e8f14985 authored by David Maul's avatar David Maul :crab:
Browse files

fix: fix invalid timings and wrong byte order in send_byte function

parent c11f0e91
No related branches found
No related tags found
No related merge requests found
......@@ -16,10 +16,12 @@
#define CLASS_NAME "amogus_class"
#define SLOTS 4
#define SLOT_INTERVAL_NS 1000000
#define SLOT_INTERVAL_NS 10000000
#define MAX_VALUES 16
#define BAUD_RATE 9600
#define BIT_TIME_US (1000000 / BAUD_RATE)
#define GPIO_PIN 575
static int major_number;
......@@ -101,23 +103,29 @@ static enum hrtimer_restart timer_callback(struct hrtimer *timer) {
return HRTIMER_RESTART;
}
static void send_bit(uint8_t bit) {
static inline void send_bit(uint8_t bit) {
gpio_set_value(GPIO_PIN, bit);
udelay(1);
udelay(BIT_TIME_US);
}
static void send_byte(uint8_t byte) {
static inline void send_byte(uint8_t byte) {
send_bit(0);
for (int i = 0; i < 8; i++) {
int bit = (byte >> (7 - i)) & 1;
send_bit(bit);
}
send_bit((byte >> 0) & 1);
send_bit((byte >> 1) & 1);
send_bit((byte >> 2) & 1);
send_bit((byte >> 3) & 1);
send_bit((byte >> 4) & 1);
send_bit((byte >> 5) & 1);
send_bit((byte >> 6) & 1);
send_bit((byte >> 7) & 1);
send_bit(1);
}
static void send_data(const packet_t *packet) {
send_byte(0xAA);
/*
send_byte(packet->data.sensor_id);
send_byte(packet->data.count);
......@@ -132,6 +140,7 @@ static void send_data(const packet_t *packet) {
for (size_t i = 0; i < sizeof(uint32_t); i++) {
send_byte(bytes[i]);
}
*/
}
static int timed_thread_fn(void *args) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment