Page 176 - MDP2022-2
P. 176

i  =  0;


            }


            char  get_button(void)  {
                  uint8_t  dt[2];
                  uint8_t  button;


                  dt[0]  =  KEYPAD_UPDATE_FIFO;
                  dt[1]  =  0x01;
                  res  =  HAL_I2C_Master_Transmit(&hi2c2,  QWIIC_KEYPAD_ADDR,  dt,  2,  10);
                  //  HAL_I2C_Master_Transmit_DMA(&hi2c2,  QWIIC_KEYPAD_ADDR,  dt,  2);
                  dt[0]  =  KEYPAD_BUTTON;
                  res  =  HAL_I2C_Master_Transmit(&hi2c2,  QWIIC_KEYPAD_ADDR,  dt,  1,  10);
                  //res  =  HAL_I2C_Master_Receive_DMA(&hi2c2,  QWIIC_KEYPAD_ADDR,  &button,  1);
                  //res  =  HAL_I2C_Master_Transmit_DMA(&hi2c2,  QWIIC_KEYPAD_ADDR,  dt,  1);
                  res  =  HAL_I2C_Master_Receive(&hi2c2,  QWIIC_KEYPAD_ADDR,  &button,  1,  10);
                  return  button;
            }


            void  set_tone(uint16_t  tone)  {
                  htim3.Instance->ARR  =  melody[tone]  -  1;
                  htim3.Instance->CCR1  =  (melody[tone]  -  1)  *  50  /  100;
            }


            void  _ham(void)  {
                  for  (int  i  =  0;  i  <  7;  i++)  {
                        set_tone(i);
                        HAL_Delay(500);
                        htim3.Instance->CCR1  =  0;
                        HAL_Delay(500);
                  }
            }


            void  HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef  *htim)  {
                  if  (htim->Instance  ==  TIM1)
                        HAL_TIM_PWM_Stop_DMA(&htim1,  TIM_CHANNEL_1);
                  datasentflag  =  1;
            }


            /*  USER  CODE  END  0  */


            /**
                *  @brief    The  application  entry  point.
                *  @retval  int
   171   172   173   174   175   176   177   178   179   180   181