Beispiel #1
0
void startDisplay(void) {


    ssd1306Init(SSD1306_SWITCHCAPVCC);
    ssd1306TurnOn();
    display.state = DISPLAY_ON;

    ssd1306DrawString(40, 20, "OpenQS", Font_System7x8);
    chThdSleepMilliseconds(100); // Fails

    serDbg("startDisplay Complete\r\n");

    while (true) {

        serDbg("Display OFF\r\n");
        ssd1306TurnOff();
        display.state = DISPLAY_OFF;

        while (!BUTTON_SEL) /* Wait until the select button is pressed */
        {
            palTogglePad(GPIOC, GPIOC_LED4); /* Display heartbeat */
            chThdSleepMilliseconds(250);
        }
        serDbg("Display ON\r\n");
        ssd1306ClearScreen();
        ssd1306TurnOn();
        display.state = DISPLAY_ON;
        openMenu(&mainMenu);
    }
}
Beispiel #2
0
int test_oled2(void)
{
    ssd1306Init(0);
    ssd1306ClearScreen();
    ssd1306DrawBmp(pic_battery_level, 120, 0, 8, 8);
    ssd1306Refresh();
    HAL_Delay(4000);

    return 0;
}
Beispiel #3
0
void test_Oled(void)
{
  int i;

  ExpanderSetbit(7,0);
  HAL_Delay(100);
  ExpanderSetbit(7,1);
  HAL_Delay(100);

  ssd1306Init(0);
  ssd1306ClearScreen();
  ssd1306Refresh();

  ssd1306DrawBmp(Pacabot_bmp, 1, 10, 128, 40);
  ssd1306Refresh();
  HAL_Delay(3500);
  ssd1306ClearScreen();
  ssd1306Refresh();
  // miniature bitmap display
  ssd1306DrawCircle(40, 30, 20);
//  ssd1306DrawCircle(50, 20, 10);
  ssd1306FillCircle(100, 40, 15);
  ssd1306DrawRect(110, 3, 15, 6);
  ssd1306FillRect(1, 60, 10, 20);
  ssd1306DrawLine(5, 45, 70, 60);
  ssd1306Refresh();
  HAL_Delay(5500);
  ssd1306ClearScreen();

  for (i = 0; i <= 100; i+=2)
  {
      ssd1306ProgressBar(10, 20, i);
//      HAL_Delay(1);
      ssd1306Refresh();
  }

  ssd1306ShiftFrameBuffer(8);
  ssd1306DrawString(13, 1, "Oled 128x64", &Font_8x8); // 3x6 is UPPER CASE only
  ssd1306Refresh();
  HAL_Delay(1500);
  ssd1306DrawString(1, 25, "Driver for STM32f4xx", &Font_5x8); // 3x6 is UPPER CASE only
  ssd1306Refresh();
  HAL_Delay(500);
  ssd1306DrawString(1, 35, "2 Wire SPI mode", &Font_5x8); // 3x6 is UPPER CASE only
  ssd1306Refresh();
  HAL_Delay(1500);
  ssd1306DrawString(10, 55, "BY PLF, PACABOT TEAM", &Font_3x6); // 3x6 is UPPER CASE only
  ssd1306Refresh();
  HAL_Delay(5000);

  ssd1306ClearScreen();
  ssd1306Refresh();
}
Beispiel #4
0
void test_EasterEgg(void)
{
	ExpanderSetbit(7,0);
	HAL_Delay(100);
	ExpanderSetbit(7,1);
	HAL_Delay(100);

	ssd1306Init(0);
	ssd1306ClearScreen();
	ssd1306Refresh();

	// I2C
	uint8_t aTxBuffer[3]; // = {control, c};
	aTxBuffer[0] = 0x0;
	aTxBuffer[1] = 0x1;
	aTxBuffer[2] = 0x5;

	uint8_t aRxBuffer[1]; // = {control, c};
	aRxBuffer[0] = 0x0;

	ssd1306ClearScreen();

	while(HAL_I2C_Master_Transmit(&hi2c1, (uint16_t)0x50<<1, (uint8_t*)aTxBuffer, 3, 10000)!= HAL_OK)
	{
	  /* Error_Handler() function is called when Timout error occurs.
		 When Acknowledge failure ocucurs (Slave don't acknowledge it's address)
		 Master restarts communication */
	  if (HAL_I2C_GetError(&hi2c1) != HAL_I2C_ERROR_AF)
	  {
		  ssd1306PrintInt(10,  15, "Bad Send", 0, &Font_5x8);
	  }

	}

	while(HAL_I2C_Master_Receive(&hi2c1, (uint16_t)0x50<<1, (uint8_t*)aRxBuffer, 1, 10000)!= HAL_OK)
	{
	  /* Error_Handler() function is called when Timout error occurs.
		 When Acknowledge failure ocucurs (Slave don't acknowledge it's address)
		 Master restarts communication */
	  if (HAL_I2C_GetError(&hi2c1) != HAL_I2C_ERROR_AF)
	  {
		  ssd1306PrintInt(10,  25, "Bad recv", 0, &Font_5x8);
	  }

	}

	ssd1306PrintInt(10,  35, "Fini : ", aRxBuffer[0], &Font_5x8);
	ssd1306Refresh();

}
Beispiel #5
0
void test_Telemeters(void)
{
	  Telemeters_Init();
	  ssd1306Init(0);
	  while(1)
	  {
		  ssd1306ClearScreen();
		  ssd1306PrintInt(10, 5,  "LFRONT  = ", (int) L_front_distance, &Font_5x8);
		  ssd1306PrintInt(10, 15, "RFRONT  = ", (int) R_front_distance, &Font_5x8);
		  ssd1306PrintInt(10, 25, "LDIAG   = ", (int) L_diag_distance, &Font_5x8);
		  ssd1306PrintInt(10, 35, "RDIAG   = ", (int) R_diag_distance, &Font_5x8);
		  ssd1306Refresh();
	  }
}
Beispiel #6
0
int test_oled1(void)
{
    int i;

    ssd1306Init(0);
    ssd1306Refresh();
    ssd1306ClearScreen();
    ssd1306DrawBmp(Pacabot_bmp, 1, 1, 128, 40);
    ssd1306Refresh();
    HAL_Delay(3500);
    ssd1306ClearScreen();
    ssd1306Refresh();
    // miniature bitmap display
    ssd1306DrawCircle(40, 30, 20);
    //  ssd1306DrawCircle(50, 20, 10);
    ssd1306FillCircle(100, 40, 15);
    ssd1306DrawRect(110, 3, 15, 6);
    ssd1306FillRect(1, 60, 10, 20);
    ssd1306DrawLine(5, 45, 70, 60);
    ssd1306Refresh();
    HAL_Delay(5500);
    ssd1306ClearScreen();

    for (i = 0; i <= 100; i++)
    {
        ssd1306ProgressBar(10, 20, i);
        HAL_Delay(1);
        ssd1306Refresh();
    }

    ssd1306ShiftFrameBuffer(8);
    ssd1306DrawString(13, 1, "Oled 128x64", &Font_8x8); // 3x6 is UPPER CASE only
    ssd1306Refresh();
    HAL_Delay(1500);
    ssd1306DrawString(1, 25, "Driver for STM32f10x", &Font_5x8); // 3x6 is UPPER CASE only
    ssd1306Refresh();
    HAL_Delay(500);
    ssd1306DrawString(1, 35, "4 Wire SPI mode", &Font_5x8); // 3x6 is UPPER CASE only
    ssd1306Refresh();
    HAL_Delay(1500);
    ssd1306DrawString(10, 55, "BY PLF ALL RIGHTS RESERVED", &Font_3x6); // 3x6 is UPPER CASE only
    ssd1306Refresh();
    HAL_Delay(5000);

    ssd1306ClearScreen();
    ssd1306Refresh();

    return 0;
}
Beispiel #7
0
int test_oled3(void)
{
    //int i;

    ssd1306Init(0);
    ssd1306ClearScreen();
    ssd1306DrawBmp(cafard, 12, 0, 103, 64);
    ssd1306Refresh();

//    for (i = 0; i < 10; i++)
//    {
//        hal_os_sleep(500);
//        ssd1306InvertArea(39, 39, 10, 10);
//        ssd1306Refresh();
//    }

    HAL_Delay(10000);

    return 0;
}
Beispiel #8
0
void test_Gyro(void)
{
	ADXRS620_Init();
	ssd1306Init(0);
	while(1)
	{
	  ssd1306ClearScreen();
	  ssd1306PrintInt(10,  25, "Angle = ", (int) gyro_Current_Angle, &Font_5x8);
	  int y = 0;
	  for(int i = 0; i<100; i++)
	  {
		  y +=  uhADCxConvertedValue_Gyro, &Font_5x8;
		  HAL_Delay(1);
	  }

	  ssd1306PrintInt(10,  35, "Adc   = ",  ((y/100)*3300)/4095, &Font_5x8);

	  ssd1306Refresh();
	}
}
Beispiel #9
0
void test_Encoders(void)
{
	  ssd1306Init(0);
	  ssd1306ClearScreen();
	  ssd1306Refresh();

	  Encoders_Init();

	  while(1)
	  {
		  ssd1306ClearScreen();
//		  ssd1306PrintInt(0, 6, "REV = ", toto, &Font_3x6);
//		  ssd1306PrintInt(0, 13, "CNT = ",  (&htim1)->Instance->CNT, &Font_3x6);
		  ssd1306PrintInt(0, 7, "L_REV =  ", left_encoder.nb_revolutions, &Font_3x6);
		  ssd1306PrintInt(0, 14, "L_CNT =  ",  __HAL_TIM_GetCounter(&htim1), &Font_3x6);
		  ssd1306PrintInt(0, 21, "L_DIR =  ",  __HAL_TIM_DIRECTION_STATUS(&htim1), &Font_3x6);

		  ssd1306PrintInt(0, 35, "R_REV =  ", right_encoder.nb_revolutions, &Font_3x6);
		  ssd1306PrintInt(0, 42, "R_CNT =  ",  __HAL_TIM_GetCounter(&htim3), &Font_3x6);
		  ssd1306PrintInt(0, 49, "R_DIR =  ",  __HAL_TIM_DIRECTION_STATUS(&htim3), &Font_3x6);
		  ssd1306Refresh();
		  HAL_Delay(10);
	  }
}
Beispiel #10
0
void test_Vbat(void)
{
	  ADC_ChannelConfTypeDef sConfig;
	  int vbat;
	  int vref = 3300;  //mV
	  int coeff = 33;  //%

	  ExpanderSetbit(7,0);
	  HAL_Delay(100);
	  ExpanderSetbit(7,1);
	  HAL_Delay(100);

	  ssd1306Init(0);
	  ssd1306ClearScreen();
	  ssd1306Refresh();

	  while(1)
	  {
	  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, SET);
	  ssd1306ClearScreen();
	  HAL_ADC_Stop_DMA(&hadc1);
	  sConfig.Channel = ADC_CHANNEL_15;
	  sConfig.Rank = 1;
	  sConfig.SamplingTime = ADC_SAMPLETIME_56CYCLES;
	  HAL_ADC_ConfigChannel(&hadc1, &sConfig);
	  HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&uhADCxConvertedValue_8, 1);

	  vbat = (((vref * uhADCxConvertedValue_8) / 40950) * coeff);

	  ssd1306PrintInt(10,  5, "Vbat =  ", vbat, &Font_5x8);
	  ssd1306Refresh();
	  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, RESET);
	  HAL_Delay(100);
	  }

}
Beispiel #11
0
int main(void)
{

    /* USER CODE BEGIN 1 */
    CMDLINE_CONTEXT cmd_context;
    const char *zhonx_info = (char *)CONFIG_ZHONX_INFO_ADDR;
    /* USER CODE END 1 */

    /* MCU Configuration----------------------------------------------------------*/

    /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
    HAL_Init();

    /* Configure the system clock */
    SystemClock_Config();

    /* Initialize all configured peripherals */
    MX_GPIO_Init();
    MX_DMA_Init();
    MX_ADC1_Init();
    MX_ADC2_Init();
    MX_ADC3_Init();
    MX_I2C1_Init();
    MX_RNG_Init();
    MX_TIM1_Init();
    MX_TIM2_Init();
    MX_TIM3_Init();
    MX_TIM4_Init();
    MX_TIM5_Init();
    MX_TIM6_Init();
    MX_TIM7_Init();
    MX_TIM8_Init();
    MX_TIM11_Init();
    MX_USART3_UART_Init();

    /* USER CODE BEGIN 2 */
    expanderInit();
    HAL_Delay(100);
    mainControlInit();
    ssd1306Init(0);
    timesBaseInit();
    ledPowerBlink(990, 10);
    settingsInit();
    mulimeterInit();
    bluetoothInit();
    toneInit();
    spyPostInit();

    positionControlSetPositionType(GYRO);
    mainControlSetFollowType(NO_FOLLOW);

    toneSetVolulme(100);
    tone(F4, 50);
    toneItMode(A4, 50);

    // Register Output callback
    cmd_context.out = blockingPrintf;
    // Initialize Command Line module
    cmdline_init(&cmd_context);

    // Check if robot name is populated in Flash
    memset(zhonxName, 0, sizeof(zhonxName));
    // Retrieve ZHONX information from flash if any
    if (zhonx_info[0] == 'Z')
    {
        strcpy(zhonxName, zhonx_info);
    }

    while (zhonxName[0] == 0)
    {
        menu(zhonxNameMenu);
    }

    while (1)
    {
        menu(mainMenu);
        powerOffConfirmation();
    }

    /* USER CODE END 2 */

    /* Infinite loop */
    /* USER CODE BEGIN WHILE */
    while (1)
        ;
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */

    /* USER CODE END 3 */

}
Beispiel #12
0
int main(void)
{

  /* USER CODE BEGIN 1 */
  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* System interrupt init*/
  /* Sets the priority grouping field */
  HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_1);
  HAL_NVIC_SetPriority(SysTick_IRQn, 0, 1);

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_ADC1_Init();
  MX_I2C1_Init();
  MX_TIM1_Init();
  MX_TIM3_Init();
  MX_TIM4_Init();
  MX_TIM6_Init();
  MX_TIM7_Init();
  MX_TIM8_Init();
  MX_TIM10_Init();
  MX_USART3_UART_Init();

  /* USER CODE BEGIN 2 */
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, SET);

  /* USER CODE END 2 */

  /* USER CODE BEGIN 3 */
//  test_Expander();
  ssd1306Init(0);
  test_Telemeters();
  ADXRS620_Init();
  TimesBase_Init();

  test_Encoders();

  Straight_Control_Start(GYRO);
  test_Beeper();
  Led_Power_Blink(990, 10, 0);
  //test_Gyro();
  Debug_ADXRS620();

//Debug_Straight_Control();
while(1);

//  test_Encoders();
//  test_Vbat();
//  test_EasterEgg();
//test_Gyro();
// test_Motor_Move();

//    test_Motors();

//  test_Telemeters();
//  HAL_Delay(1000);
//  test_LineSensors();
//  test_Oled();
//  test_IR_Sensors();

  /* USER CODE END 3 */

}
Beispiel #13
0
void systemInit()
{
  cpuInit();
  systickInit((CFG_CPU_CCLK / 1000) * CFG_SYSTICK_DELAY_IN_MS);
  gpioInit();
  pmuInit();
  adcInit();    // Init adc pins to avoid wasting 60uA in deep sleep

  #ifdef CFG_PRINTF_UART
    // Initialise UART with the default baud rate (set in projectconfig.h)
    uartInit(CFG_UART_BAUDRATE);
  #endif

  // Switch to 3.3V if TPS780 (etc.) is being used
  #if defined CFG_VREG_ALT_PRESENT && CFG_VREG_ALT_PRESENT == 1
    gpioSetDir(CFG_VREG_ALT_PORT, CFG_VREG_ALT_PIN, gpioDirection_Output);
    gpioSetValue(CFG_VREG_ALT_PORT, CFG_VREG_ALT_PIN, 0);
    gpioSetPullup(&CFG_VREG_ALT_REG32, gpioPullupMode_Inactive);
  #endif

  // Set LED pin as output and turn LED off
  gpioSetDir(CFG_LED_PORT, CFG_LED_PIN, 1);
  gpioSetValue(CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF);

  // Initialise the ST7565 128x64 pixel display
  #ifdef CFG_ST7565
    st7565Init();
    st7565ClearScreen();    // Clear the screen  
    st7565Backlight(1);     // Enable the backlight
  #endif

  // Initialise the SSD1306 OLED display
  #ifdef CFG_SSD1306
    ssd1306Init(SSD1306_SWITCHCAPVCC);
    ssd1306ClearScreen();   // Clear the screen  
  #endif

  // Initialise EEPROM
  #ifdef CFG_I2CEEPROM
    mcp24aaInit();
  #endif

  // Initialise Chibi
  #ifdef CFG_CHIBI
    // Write addresses to EEPROM for the first time if necessary
    // uint16_t addr_short = 0x1166;
    // uint64_t addr_ieee =  addr_short;
    // mcp24aaWriteBuffer(CFG_CHIBI_EEPROM_SHORTADDR, (uint8_t *)&addr_short, 2);
    // mcp24aaWriteBuffer(CFG_CHIBI_EEPROM_IEEEADDR, (uint8_t *)&addr_ieee, 8);
    chb_init();
  #endif

  // Setup SD Card
  #ifdef CFG_SDCARD
    // Turn off SD card by default (saves power)
    gpioSetDir(CFG_SDCARD_ENPORT, CFG_SDCARD_ENPIN, gpioDirection_Output); /* Set enable pin to output */
    gpioSetValue(CFG_SDCARD_ENPORT, CFG_SDCARD_ENPIN, 0);                  /* Disable card by setting ENPIN low */
    gpioSetPullup(&CFG_SDCARD_ENREG32, gpioPullupMode_Inactive);
  #endif

  #ifdef CFG_LM75B
    // Initialise LM75B
    lm75bInit();
    // Read temp once to make sure we are in sleep mode
    int32_t temp;
    lm75bGetTemperature(&temp);
  #endif

  #ifdef CFG_BAT
    // Turn off battery voltage divider by default
    gpioSetDir(CFG_BAT_ENPORT, CFG_BAT_ENPIN, gpioDirection_Output );   // Set voltage divider enable pin to output
    gpioSetValue(CFG_BAT_ENPORT, CFG_BAT_ENPIN, 0 );                    // Disable the voltage divider by default
    gpioSetPullup(&CFG_BAT_ENREG32, gpioPullupMode_Inactive);
  #endif

  // Start the command line interface (if requested)
  #ifdef CFG_INTERFACE
    printf("%sType '?' for a list of available commands%s", CFG_PRINTF_NEWLINE, CFG_PRINTF_NEWLINE);
    cmdInit();
  #endif
}
Beispiel #14
0
void test_LineSensors(void)
{
	  ADC_ChannelConfTypeDef sConfig;

	  ExpanderSetbit(7,0);
	  HAL_Delay(100);
	  ExpanderSetbit(7,1);
	  HAL_Delay(100);

	  ssd1306Init(0);
	  ssd1306ClearScreen();
	  ssd1306Refresh();

	  while(1)
	  {
	  ssd1306ClearScreen();

	  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_2, SET);
	  HAL_Delay(25);


	  HAL_ADC_Stop_DMA(&hadc1);
	  sConfig.Channel = ADC_CHANNEL_3;
	  sConfig.Rank = 1;
	  sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
	  HAL_ADC_ConfigChannel(&hadc1, &sConfig);
	  HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&uhADCxConvertedValue_1, 1);
	  ssd1306PrintInt(10,  5, "ADC3  = ", uhADCxConvertedValue_1, &Font_5x8);

	  HAL_ADC_Stop_DMA(&hadc1);
	  sConfig.Channel = ADC_CHANNEL_4;
	  sConfig.Rank = 1;
	  sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
	  HAL_ADC_ConfigChannel(&hadc1, &sConfig);
	  HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&uhADCxConvertedValue_2, 1);
	  ssd1306PrintInt(10, 15, "ADC4  = ", uhADCxConvertedValue_2, &Font_5x8);

	  HAL_ADC_Stop_DMA(&hadc1);
	  sConfig.Channel = ADC_CHANNEL_1;
	  sConfig.Rank = 1;
	  sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
	  HAL_ADC_ConfigChannel(&hadc1, &sConfig);
	  HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&uhADCxConvertedValue_3, 1);
	  ssd1306PrintInt(10, 25, "ADC1  = ", uhADCxConvertedValue_3, &Font_5x8);

	  HAL_ADC_Stop_DMA(&hadc1);
	  sConfig.Channel = ADC_CHANNEL_13;
	  sConfig.Rank = 1;
	  sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
	  HAL_ADC_ConfigChannel(&hadc1, &sConfig);
	  HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&uhADCxConvertedValue_4, 1);
	  ssd1306PrintInt(10, 35, "ADC13 = ", uhADCxConvertedValue_4, &Font_5x8);

	  HAL_ADC_Stop_DMA(&hadc1);
	  sConfig.Channel = ADC_CHANNEL_12;
	  sConfig.Rank = 1;
	  sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
	  HAL_ADC_ConfigChannel(&hadc1, &sConfig);
	  HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&uhADCxConvertedValue_5, 1);
	  ssd1306PrintInt(10, 45, "ADC12 = ", uhADCxConvertedValue_5, &Font_5x8);

	  ssd1306Refresh();

	  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_2, RESET);
	  }
}
Beispiel #15
0
void init_display()
{
	  ssd1306Init(0);
	  ssd1306ClearScreen();
	  ssd1306Refresh();
}