| // 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 <cstdint> |
| |
| #include <Arduino.h> |
| #include <SPI.h> |
| |
| #include "pw_log/log.h" |
| #include "pw_string/format.h" |
| |
| #include "gonk/pin_config.h" |
| |
| using gonk::pin_config::FlashCS; |
| using gonk::pin_config::PinConfig; |
| using gonk::pin_config::StatusLed; |
| |
| namespace { |
| |
| PinConfig pin_config = PinConfig(); |
| |
| } // 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; |
| uint8_t manufacturer_id[4]; |
| |
| while (true) { |
| |
| // Read the SPI Flash JEDEC ID. |
| manufacturer_id[0] = 0x9f; |
| manufacturer_id[1] = 0; |
| manufacturer_id[2] = 0; |
| manufacturer_id[3] = 0; |
| SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0)); |
| digitalWrite(FlashCS, LOW); |
| SPI.transfer(manufacturer_id, 4); |
| digitalWrite(FlashCS, HIGH); |
| SPI.endTransaction(); |
| |
| pw::string::Format(buffer, "SPI Flash JEDEC ID: %x %x %x", |
| manufacturer_id[1], manufacturer_id[2], |
| manufacturer_id[3]); |
| PW_LOG_INFO("%s", buffer); |
| 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; |
| } |