// Copyright 2024 The Pigweed Authors
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.

#include "device/pico_board.h"

#include "hardware/adc.h"
#include "hardware/flash.h"
#include "pico/bootrom.h"
#include "pw_bytes/endian.h"

namespace sense {

PicoBoard::PicoBoard() { adc_init(); }

// See raspberry-pi-pico-c-sdk.pdf, Section '4.1.1. hardware_adc'
float PicoBoard::ReadInternalTemperature() {
  adc_set_temp_sensor_enabled(true);
  adc_select_input(4);  // 4 is the on board temp sensor.

  constexpr float kConversionFactor = 3.3f / (1 << 12);
  float adc = static_cast<float>(adc_read()) * kConversionFactor;
  return 27.0f - (adc - 0.706f) / 0.001721f;
}

// See raspberry-pi-pico-c-sdk.pdf, Section '4.5.5. hardware_bootrom'
pw::Status PicoBoard::Reboot(board_RebootType_Enum reboot_type) {
  uint32_t disable_interface_mask = 0;

  if (reboot_type == board_RebootType_Enum_BOTH_MASS_STORAGE_AND_PICOBOOT) {
    disable_interface_mask = 0;
  } else if (reboot_type == board_RebootType_Enum_PICOBOOT_ONLY) {
    disable_interface_mask = 1;
  } else if (reboot_type == board_RebootType_Enum_MASS_STORAGE_ONLY) {
    disable_interface_mask = 2;
  } else {
    return pw::Status::Unknown();
  }

  reset_usb_boot(0, disable_interface_mask);
  return pw::OkStatus();
}

uint64_t PicoBoard::UniqueFlashId() const {
  std::array<uint8_t, 8> flash_id;
  flash_get_unique_id(flash_id.data());
  return pw::bytes::ReadInOrder<uint64_t>(pw::endian::little, flash_id);
}

}  // namespace sense