#include "stm32g0xx.h"
#include "vacuum_board.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>
RCC_TypeDef host_rcc;
GPIO_TypeDef host_gpio;
TIM_TypeDef host_tim;
SYSCFG_TypeDef host_syscfg;
EXTI_TypeDef host_exti;
ADC_TypeDef host_adc;
ADC_Common_TypeDef host_adc_common;
uint32_t SystemCoreClock = 16000000u;
static void seed(unsigned remap, unsigned timer)
{
 memset(&host_rcc,0,sizeof host_rcc);memset(&host_gpio,0,sizeof host_gpio);
 memset(&host_syscfg,0,sizeof host_syscfg);memset(&host_tim,0,sizeof host_tim);
 host_gpio.ODR = (1u<<10)|(1u<<12); /* Prior logical outputs high. */
 host_gpio.MODER = ~0u;host_gpio.OTYPER=~0u;host_gpio.PUPDR=0;
 host_syscfg.CFGR1=SYSCFG_CFGR1_PA11_RMP|(remap?SYSCFG_CFGR1_PA12_RMP:0);
 host_rcc.APBENR2 = timer?RCC_APBENR2_TIM1EN:0;host_tim.CCR1=500;
}
static void check_pad(void)
{
 assert(((host_gpio.MODER>>(12*2))&3)==1); /* Physical pin17 must be an output. */
 assert((host_rcc.IOPENR&RCC_IOPENR_GPIOAEN)!=0);
 assert((host_rcc.APBENR2&RCC_APBENR2_SYSCFGEN)!=0);
 assert((host_syscfg.CFGR1&SYSCFG_CFGR1_PA12_RMP)==0);
 assert((host_syscfg.CFGR1&SYSCFG_CFGR1_PA11_RMP)!=0); /* Other mapping preserved. */
 assert(((host_gpio.MODER>>(12*2))&3)==1); /* Package pin17, not unbonded PA10. */
 assert((host_gpio.OTYPER&(1u<<12))==0);
 assert(((host_gpio.PUPDR>>(12*2))&3)==2);
 assert((host_gpio.BSRR&(1u<<(12+16)))!=0);
 assert((host_gpio.BSRR&(1u<<12))==0);
}
int main(void)
{
 for(unsigned remap=0;remap<2;remap++) for(unsigned timer=0;timer<2;timer++) {
  seed(remap,timer);vacuum_board_force_off();check_pad();
  assert(((host_gpio.MODER>>(8*2))&3)==0);
  assert((host_gpio.BSRR&(1u<<(8+16)))!=0);
  seed(remap,timer);vacuum_board_force_fan_disabled();check_pad();
  assert(host_tim.CCR1==(timer?0:500));
  seed(remap,timer);assert(vacuum_board_set_fan_power(0,true)==-1);check_pad();
  seed(remap,timer);assert(vacuum_board_set_fan_duty(0,1000)==-1);check_pad();
 }
 puts("PASS: physical pin17 PA12 off commands, both prior remap states, timer on/off, output lock rejection; MMIO writes only, no measured voltage.");
}
