diff --git a/software/config.h b/software/config.h index 18712c8..8bcbf41 100644 --- a/software/config.h +++ b/software/config.h @@ -1,7 +1,10 @@ #ifndef _CONFIG_H #define _CONFIG_H_ -//F_xxx is in Hz +// Hardware configuration: +// #define DISP_DRIVER_ET6226 + +// F_xxx is in Hz #define F_CPU 16000000L #define F_SYSTICK 100 @@ -37,9 +40,8 @@ #define POW_ABS_MAX 65000 //mW: Current at which the load current is reduced /* Usable range: - Rmin = 1V / 10A = 0.1 Ohm - Rmax = 30V / 0.2A = 150 Ohm -*/ + Rmin = 1V / 10A = 0.1 Ohm + Rmax = 30V / 0.2A = 150 Ohm */ #define R_MIN 10 //10*mOhm #define R_MAX 15000 //10*mOhm #define R_DOT_OFFSET 2 @@ -48,8 +50,7 @@ #define WS_DOT_OFFSET 3 /* Defintion of t and m: - PWM = (current * m - t) / 2^16 -*/ + PWM = (current * m - t) / 2^16 */ #define LOAD_CAL_T 8821987L #define LOAD_CAL_M 350445L @@ -66,8 +67,7 @@ #define ADC_CAL_TEMP_M 42 #define ADC_CAL_TEMP_T 64014 /* 12V mesurement Voltage divider: 1/3 - V12V in mV = ADC * 5Vref * 3 / 2^16 * 1000mV/V = ADC * 15000 / 2^16 -*/ + V12V in mV = ADC * 5Vref * 3 / 2^16 * 1000mV/V = ADC * 15000 / 2^16 */ #define ADC_CAL_12V 15080 /* Defintion of t and m: @@ -97,14 +97,21 @@ #define PINB_ENC_A (1u<<5) #define PINB_ENC_B (1u<<4) -//port C +// port C #define PINC_I_SET (1u<<1) #define PINC_OL_DETECT (1u<<2) #define PINC_ENC_P (1u<<3) #define PINC_RUN_P (1u<<4) + +#ifdef DISP_DRIVER_ET6226 +#define PINC_SDA (1u << 5) +#define PINC_SCL1 (1u << 6) +#define PINC_SCL2 (1u << 7) +#else #define PINC_SCL (1u<<5) #define PINC_SDA1 (1u<<6) #define PINC_SDA2 (1u<<7) +#endif // port D #define PIND_FAN (1u<<0) @@ -118,11 +125,16 @@ // port E #define PINE_ENABLE (1u<<5) - - #define GPIO_DISPLAY GPIOC + +#ifdef DISP_DRIVER_ET6226 +#define DP_TOP_PIN PINC_SCL2 +#define DP_BOT_PIN PINC_SCL1 +#else #define DP_TOP_PIN PINC_SDA2 #define DP_BOT_PIN PINC_SDA1 +#endif + #define LED_V 0x01 #define LED_AH 0x02 #define LED_WH 0x04 @@ -130,4 +142,5 @@ #define LED_RUN 0x10 #define LED_DIGIT1 0x20 #define LED_DIGIT2 0x40 + #endif diff --git a/software/electronic_load.c b/software/electronic_load.c index b16284e..502160f 100644 --- a/software/electronic_load.c +++ b/software/electronic_load.c @@ -29,12 +29,20 @@ void gpio_init() GPIOB->CR1 = PINB_ENC_A | PINB_ENC_B; // Pullup GPIOB->CR2 = PINB_ENC_A | PINB_ENC_B; // Irq + +#ifdef DISP_DRIVER_ET6226 + GPIOC->DDR = PINC_I_SET | PINC_SDA | PINC_SCL1 | PINC_SCL2; + GPIOC->CR1 = PINC_I_SET | PINC_SCL1 | PINC_SCL2 | // push pull + PINC_OL_DETECT | PINC_ENC_P | PINC_RUN_P; // pullup + GPIOC->CR2 = PINC_OL_DETECT | PINC_ENC_P | PINC_RUN_P | // irq + PINC_SDA | PINC_SCL1 | PINC_SCL2; // 10 MHz +#else GPIOC->DDR = PINC_I_SET | PINC_SCL | PINC_SDA1 | PINC_SDA2; GPIOC->CR1 = PINC_I_SET | PINC_SCL | // push pull PINC_OL_DETECT | PINC_ENC_P | PINC_RUN_P; // pullup GPIOC->CR2 = PINC_OL_DETECT | PINC_ENC_P | PINC_RUN_P | // irq PINC_SCL | PINC_SDA1 | PINC_SDA2; // 10 MHz - +#endif GPIOD->DDR = PIND_FAN | PIND_BUS_F | PIND_BEEPER | PIND_TX; GPIOD->CR1 = PIND_FAN | PIND_BUS_F | PIND_BEEPER | PIND_TX | // push pull diff --git a/software/tm1650.c b/software/tm1650.c index dabdc98..14683e8 100644 --- a/software/tm1650.c +++ b/software/tm1650.c @@ -2,7 +2,6 @@ #include "config.h" #include "inc/stm8s_gpio.h" -#define PIN_I2C_CLK PINC_SCL #define DIGIT_REG 0x68 #define BRIGHTNESS_REG 0x48 @@ -67,36 +66,64 @@ static void i2c_write(uint8_t data, uint8_t pin) uint8_t i; GPIO_DISPLAY->DDR |= pin; for (i = 7; i < 255; i--) { +#ifdef DISP_DRIVER_ET6226 + if (data & (1 << i)) { + GPIO_DISPLAY->ODR |= PINC_SDA; + } else { + GPIO_DISPLAY->ODR &= ~PINC_SDA; + } + // Clock H/L + GPIO_DISPLAY->ODR |= pin; + GPIO_DISPLAY->ODR &= ~pin; + } + // We don't need the ACK, so just do a single clock H/L without reading + GPIO_DISPLAY->ODR |= pin; + GPIO_DISPLAY->ODR &= ~pin; +#else if (data & (1 << i)) { GPIO_DISPLAY->ODR |= pin; } else { GPIO_DISPLAY->ODR &= ~pin; } // Clock H/L - GPIO_DISPLAY->ODR |= PIN_I2C_CLK; - GPIO_DISPLAY->ODR &= ~PIN_I2C_CLK; + GPIO_DISPLAY->ODR |= PINC_SCL; + GPIO_DISPLAY->ODR &= ~PINC_SCL; } // We don't need the ACK, so just do a single clock H/L without reading - GPIO_DISPLAY->ODR |= PIN_I2C_CLK; - GPIO_DISPLAY->ODR &= ~PIN_I2C_CLK; + GPIO_DISPLAY->ODR |= PINC_SCL; + GPIO_DISPLAY->ODR &= ~PINC_SCL; +#endif } void disp_write(uint8_t addr, uint8_t data, uint8_t pin) { - pin = (pin == DP_TOP)?DP_TOP_PIN:DP_BOT_PIN; + pin = (pin == DP_TOP) ? DP_TOP_PIN : DP_BOT_PIN; // Start sequence - GPIO_DISPLAY->ODR |= pin; // SDA HIGH - GPIO_DISPLAY->ODR |= PIN_I2C_CLK; // SCL HIGH - GPIO_DISPLAY->ODR &= ~pin; // SDA LOW - GPIO_DISPLAY->ODR &= ~PIN_I2C_CLK; // SCL LOW +#ifdef DISP_DRIVER_ET6226 + GPIO_DISPLAY->ODR |= PINC_SDA; // SDA HIGH + GPIO_DISPLAY->ODR |= pin; // SCL HIGH + GPIO_DISPLAY->ODR &= ~PINC_SDA; // SDA LOW + GPIO_DISPLAY->ODR &= ~pin; // SCL LOW +#else + GPIO_DISPLAY->ODR |= pin; // SDA HIGH + GPIO_DISPLAY->ODR |= PINC_SCL; // SCL HIGH + GPIO_DISPLAY->ODR &= ~pin; // SDA LOW + GPIO_DISPLAY->ODR &= ~PINC_SCL; // SCL LOW +#endif i2c_write(addr, pin); i2c_write(data, pin); // Stop sequence - GPIO_DISPLAY->ODR &= ~pin; // SDA LOW - GPIO_DISPLAY->ODR |= PIN_I2C_CLK; // SCL HIGH - GPIO_DISPLAY->ODR |= pin; // SDA HIGH +#ifdef DISP_DRIVER_ET6226 + GPIO_DISPLAY->ODR &= ~PINC_SDA; // SDA LOW + GPIO_DISPLAY->ODR |= pin; // SCL HIGH + GPIO_DISPLAY->ODR |= PINC_SDA; // SDA HIGH +#else + GPIO_DISPLAY->ODR &= ~pin; // SDA LOW + GPIO_DISPLAY->ODR |= PINC_SCL; // SCL HIGH + GPIO_DISPLAY->ODR |= pin; // SDA HIGH +#endif } void disp_char(uint8_t position, uint8_t c, uint8_t dot, uint8_t pin)