This commit is contained in:
2025-12-02 02:03:04 +06:00
parent f9803a2803
commit 7e6195f967
2 changed files with 565 additions and 201 deletions

View File

@@ -3,7 +3,7 @@
#include "ch32fun.h"
// #define GPIB_DEBUG 1
#define GPIB_DEBUG 1
// Control Lines (Active LOW)
#define PIN_EOI PB3
@@ -153,14 +153,42 @@
#define GPIB_READ(pin) funDigitalRead(pin)
// Data Lines (DIO1-DIO8)
#define PIN_DIO1 PB9
#define PIN_DIO2 PB8
#define PIN_DIO3 PB5
#define PIN_DIO4 PB4
#define PIN_DIO5 PB15
#define PIN_DIO6 PB14
#define PIN_DIO7 PB13
#define PIN_DIO8 PB12
// #define PIN_DIO1 PB9
// #define PIN_DIO2 PB8
// #define PIN_DIO3 PB5
// #define PIN_DIO4 PB4
// #define PIN_DIO5 PB15
// #define PIN_DIO6 PB14
// #define PIN_DIO7 PB13
// #define PIN_DIO8 PB12
// Physical Pin mappings on PORT B
#define PIN_DIO1 9 // PB9
#define PIN_DIO2 8 // PB8
#define PIN_DIO3 5 // PB5
#define PIN_DIO4 4 // PB4
#define PIN_DIO5 15 // PB15
#define PIN_DIO6 14 // PB14
#define PIN_DIO7 13 // PB13
#define PIN_DIO8 12 // PB12
#define SHIFT_DIO1 (PIN_DIO1 - 0) // 9
#define SHIFT_DIO2 (PIN_DIO2 - 1) // 7
#define SHIFT_DIO3 (PIN_DIO3 - 2) // 3
#define SHIFT_DIO4 (PIN_DIO4 - 3) // 1
#define SHIFT_DIO5 (PIN_DIO5 - 4) // 11
#define SHIFT_DIO6 (PIN_DIO6 - 5) // 9
#define SHIFT_DIO7 (PIN_DIO7 - 6) // 7
#define SHIFT_DIO8 (PIN_DIO8 - 7) // 5
// pins that share the same shift amount
// Group A: shift right 9 (PB9->Bit0, PB14->Bit5)
#define MASK_GROUP_A ((1 << 0) | (1 << 5))
// Group B: shift right 7 (PB8->Bit1, PB13->Bit6)
#define MASK_GROUP_B ((1 << 1) | (1 << 6))
#define CALC_PIN_BSHR(val, bit_idx, pin_num) \
((val & (1 << bit_idx)) ? (1U << (pin_num + 16)) : (1U << pin_num))
#define MASK_DIO1 (1U << 9)
#define MASK_DIO2 (1U << 8)
@@ -171,7 +199,7 @@
#define MASK_DIO7 (1U << 13)
#define MASK_DIO8 (1U << 12)
static const int DIO_PINS[] = {PIN_DIO1, PIN_DIO2, PIN_DIO3, PIN_DIO4,
PIN_DIO5, PIN_DIO6, PIN_DIO7, PIN_DIO8};
// static const int DIO_PINS[] = {PIN_DIO1, PIN_DIO2, PIN_DIO3, PIN_DIO4,
// PIN_DIO5, PIN_DIO6, PIN_DIO7, PIN_DIO8};
#endif

716
main.c

File diff suppressed because it is too large Load Diff