blob: daaaa048bcc3cfcf18ec5ec68edad04ed111f6d7 [file] [log] [blame]
// Copyright 2023 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 <bitset>
#include <cstdint>
#include <Arduino.h>
#include <SPI.h>
#include "pw_log/log.h"
#include "pw_result/result.h"
#include "pw_string/format.h"
#include "gonk/pin_config.h"
#include "gonk/spi_flash.h"
using gonk::pin_config::FlashCS;
using gonk::pin_config::PinConfig;
using gonk::pin_config::StatusLed;
using gonk::spi_flash::SpiFlash;
namespace {
PinConfig pin_config = PinConfig();
SpiFlash spi_flash = SpiFlash(FlashCS, /*baudrate=*/1000000);
} // namespace
int main() {
pin_config.Init();
// Put FPGA in reset.
pin_config.InitFpgaPins();
pin_config.FpgaHalt();
delay(10);
pin_config.SPIEnable();
char buffer[32];
uint16_t update_count = 0;
while (true) {
PW_LOG_INFO("Update Count: %d", update_count);
pw::Result<SpiFlash::DeviceId> result = spi_flash.GetDeviceIds();
if (result.ok()) {
PW_LOG_INFO("SPI Flash JEDEC ID: %x %x %x",
result.value().manufacturer_id, result.value().family_code,
result.value().product_version);
}
delay(1000);
update_count = (update_count + 1) % UINT16_MAX;
// Toggle status LED each loop.
if (update_count % 2 == 0) {
digitalWrite(StatusLed, HIGH);
} else {
digitalWrite(StatusLed, LOW);
}
}
return 0;
}