Only enable the bus when needed
This commit is contained in:
		
							parent
							
								
									baa7e1bf12
								
							
						
					
					
						commit
						2194a339cf
					
				@ -72,8 +72,10 @@ void TwiMaster::Init() {
 | 
			
		||||
 | 
			
		||||
TwiMaster::ErrorCodes TwiMaster::Read(uint8_t deviceAddress, uint8_t registerAddress, uint8_t* data, size_t size) {
 | 
			
		||||
  xSemaphoreTake(mutex, portMAX_DELAY);
 | 
			
		||||
  Wakeup();
 | 
			
		||||
  auto ret = Write(deviceAddress, ®isterAddress, 1, false);
 | 
			
		||||
  ret = Read(deviceAddress, data, size, true);
 | 
			
		||||
  Sleep();
 | 
			
		||||
  xSemaphoreGive(mutex);
 | 
			
		||||
  return ret;
 | 
			
		||||
}
 | 
			
		||||
@ -81,9 +83,11 @@ TwiMaster::ErrorCodes TwiMaster::Read(uint8_t deviceAddress, uint8_t registerAdd
 | 
			
		||||
TwiMaster::ErrorCodes TwiMaster::Write(uint8_t deviceAddress, uint8_t registerAddress, const uint8_t* data, size_t size) {
 | 
			
		||||
  ASSERT(size <= maxDataSize);
 | 
			
		||||
  xSemaphoreTake(mutex, portMAX_DELAY);
 | 
			
		||||
  Wakeup();
 | 
			
		||||
  internalBuffer[0] = registerAddress;
 | 
			
		||||
  std::memcpy(internalBuffer + 1, data, size);
 | 
			
		||||
  auto ret = Write(deviceAddress, internalBuffer, size + 1, true);
 | 
			
		||||
  Sleep();
 | 
			
		||||
  xSemaphoreGive(mutex);
 | 
			
		||||
  return ret;
 | 
			
		||||
}
 | 
			
		||||
@ -179,13 +183,11 @@ void TwiMaster::Sleep() {
 | 
			
		||||
  }
 | 
			
		||||
  nrf_gpio_cfg_default(6);
 | 
			
		||||
  nrf_gpio_cfg_default(7);
 | 
			
		||||
  NRF_LOG_INFO("[TWIMASTER] Sleep");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TwiMaster::Wakeup() {
 | 
			
		||||
  ConfigurePins();
 | 
			
		||||
  twiBaseAddress->ENABLE = (TWIM_ENABLE_ENABLE_Enabled << TWIM_ENABLE_ENABLE_Pos);
 | 
			
		||||
  NRF_LOG_INFO("[TWIMASTER] Wakeup");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Sometimes, the TWIM device just freeze and never set the event EVENTS_LASTTX.
 | 
			
		||||
 | 
			
		||||
@ -219,7 +219,6 @@ void SystemTask::Work() {
 | 
			
		||||
          break;
 | 
			
		||||
        case Messages::GoToRunning:
 | 
			
		||||
          spi.Wakeup();
 | 
			
		||||
          twiMaster.Wakeup();
 | 
			
		||||
 | 
			
		||||
          // Double Tap needs the touch screen to be in normal mode
 | 
			
		||||
          if (!settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) {
 | 
			
		||||
@ -240,9 +239,7 @@ void SystemTask::Work() {
 | 
			
		||||
          isDimmed = false;
 | 
			
		||||
          break;
 | 
			
		||||
        case Messages::TouchWakeUp: {
 | 
			
		||||
          twiMaster.Wakeup();
 | 
			
		||||
          auto touchInfo = touchPanel.GetTouchInfo();
 | 
			
		||||
          twiMaster.Sleep();
 | 
			
		||||
          if (touchInfo.isTouch and ((touchInfo.gesture == Pinetime::Drivers::Cst816S::Gestures::DoubleTap and
 | 
			
		||||
                                      settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) or
 | 
			
		||||
                                     (touchInfo.gesture == Pinetime::Drivers::Cst816S::Gestures::SingleTap and
 | 
			
		||||
@ -315,7 +312,6 @@ void SystemTask::Work() {
 | 
			
		||||
          if (!settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) {
 | 
			
		||||
            touchPanel.Sleep();
 | 
			
		||||
          }
 | 
			
		||||
          twiMaster.Sleep();
 | 
			
		||||
 | 
			
		||||
          isSleeping = true;
 | 
			
		||||
          isGoingToSleep = false;
 | 
			
		||||
@ -367,17 +363,12 @@ void SystemTask::UpdateMotion() {
 | 
			
		||||
  if (isSleeping && !settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist))
 | 
			
		||||
    return;
 | 
			
		||||
 | 
			
		||||
  if (isSleeping)
 | 
			
		||||
    twiMaster.Wakeup();
 | 
			
		||||
 | 
			
		||||
  if (stepCounterMustBeReset) {
 | 
			
		||||
    motionSensor.ResetStepCounter();
 | 
			
		||||
    stepCounterMustBeReset = false;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  auto motionValues = motionSensor.Process();
 | 
			
		||||
  if (isSleeping)
 | 
			
		||||
    twiMaster.Sleep();
 | 
			
		||||
 | 
			
		||||
  motionController.IsSensorOk(motionSensor.IsOk());
 | 
			
		||||
  motionController.Update(motionValues.x, motionValues.y, motionValues.z, motionValues.steps);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user