Skip to content

Commit

Permalink
Wire up the sbr service into the app (#155)
Browse files Browse the repository at this point in the history
This is the culmination of several PRs, allowing us to bind this service
to this app.

See
#155 (comment)
for my log of notes along the way.

Here are the related PRs:
- #153 
- #152 
- #151 
- #150 
- #143 
- #142 
- #141 
- #140 
- #138 

And the created/related issues:
- #154 
- #149 
- #148
- #147 
- #145 
- #144 
- #139 
- #125
  • Loading branch information
michael-christen authored Nov 12, 2024
1 parent 5f74cf4 commit e0b6b35
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 4 deletions.
1 change: 1 addition & 0 deletions apps/sbr/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ cc_binary(
srcs = ["main.cc"],
deps = [
"//apps/sbr/system",
"//hw_services/sbr:service",
"@pigweed//pw_log",
"@pigweed//pw_system:async",

Expand Down
10 changes: 10 additions & 0 deletions apps/sbr/main.cc
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
#define PW_LOG_MODULE_NAME "MAIN"

#include "apps/sbr/system/system.h"
#include "hw_services/sbr/service.h"
#include "pw_log/log.h"
#include "pw_system/system.h"

int main() {
apps::sbr::system::Init();

auto& rpc_server = pw::System().rpc_server();

static hw_services::sbr::SbrService sbr_service;

auto& reg_device = apps::sbr::system::LIS3MDLRegisterDevice();
sbr_service.Init(pw::System().dispatcher(), pw::System().allocator(),
&reg_device);
rpc_server.RegisterService(sbr_service);

PW_LOG_INFO("Started SBR app; waiting for RPCs...");
apps::sbr::system::Start();
PW_UNREACHABLE;
Expand Down
12 changes: 12 additions & 0 deletions apps/sbr/system/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ cc_library(
"system.h",
],
visibility = ["//visibility:public"],
deps = [
"@pigweed//pw_i2c:register_device",
],
)

cc_library(
Expand All @@ -27,7 +30,10 @@ cc_library(
"host_system.cc",
],
implementation_deps = [
"//platforms/host:initiator_host",
"//third_party/pigweed/system:common_host_system",
"@pigweed//pw_i2c:address",
"@pigweed//pw_i2c:register_device",
"@pigweed//pw_system:async",
],
target_compatible_with = incompatible_with_mcu(),
Expand All @@ -39,8 +45,14 @@ cc_library(
srcs = [
"rp2_system.cc",
],
implementation_deps = [
"@pigweed//pw_i2c:address",
"@pigweed//pw_i2c:register_device",
"@pigweed//pw_i2c_rp2040",
],
deps = [
"//apps/sbr/system:headers",
"//hw_drivers/lis3mdl",
"//third_party/pigweed/system:common_rp2_system",
],
)
16 changes: 13 additions & 3 deletions apps/sbr/system/host_system.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "apps/sbr/system/system.h"
#include "platforms/host/initiator_host.h"
#include "pw_i2c/address.h"
#include "third_party/pigweed/system/common_host_system.h"

namespace apps {
Expand All @@ -7,9 +9,17 @@ namespace system {

void Init() {}

void Start() {
// third_party::pigweed::system::
PW_HOST_SYSTEM_START(16384, "//apps/sbr:simulator_console")
void Start(){// third_party::pigweed::system::
PW_HOST_SYSTEM_START(16384, "//apps/sbr:simulator_console")}

pw::i2c::RegisterDevice& LIS3MDLRegisterDevice() {
constexpr pw::i2c::Address kAddress = pw::i2c::Address::SevenBit<0x01>();

static platforms::host::HostInitiator initiator;
static pw::i2c::RegisterDevice reg_device(
initiator, kAddress, cpp20::endian::little,
pw::i2c::RegisterAddressSize::k1Byte);
return reg_device;
}

} // namespace system
Expand Down
35 changes: 34 additions & 1 deletion apps/sbr/system/rp2_system.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
#include "apps/sbr/system/system.h"
#include "hw_drivers/lis3mdl/lis3mdl.h"
#include "pw_i2c_rp2040/initiator.h"

namespace {

pw::i2c::Initiator& I2cInitiator() {
constexpr unsigned int kPinSda = 4;
constexpr unsigned int kPinScl = 5;

static constexpr pw::i2c::Rp2040Initiator::Config kI2c0Config{
.clock_frequency = 400'000,
.sda_pin = kPinSda,
.scl_pin = kPinScl,
};

static pw::i2c::Initiator& i2c0_bus = []() -> pw::i2c::Initiator& {
static pw::i2c::Rp2040Initiator bus(kI2c0Config, i2c0);
bus.Enable();
return bus;
}();

return i2c0_bus;
}

} // namespace

#include "third_party/pigweed/system/common_rp2_system.h"

namespace apps {
Expand All @@ -7,7 +33,14 @@ namespace system {

void Init() { third_party::pigweed::system::CommonRp2Init(); }

void Start() { PW_RP2_SYSTEM_START(2048) }
void Start(){PW_RP2_SYSTEM_START(2048)}

pw::i2c::RegisterDevice& LIS3MDLRegisterDevice() {
static pw::i2c::RegisterDevice reg_device(
I2cInitiator(), hw_drivers::lis3mdl::kHighAddress, cpp20::endian::little,
pw::i2c::RegisterAddressSize::k1Byte);
return reg_device;
}

} // namespace system
} // namespace sbr
Expand Down
3 changes: 3 additions & 0 deletions apps/sbr/system/system.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "pw_i2c/register_device.h"
// The functions in this file return specific implementations of singleton types
// provided by the system.

Expand All @@ -13,6 +14,8 @@ void Init();
/// Starts the main system scheduler. This function never returns.
[[noreturn]] void Start();

pw::i2c::RegisterDevice& LIS3MDLRegisterDevice();

} // namespace system
} // namespace sbr
} // namespace apps
1 change: 1 addition & 0 deletions hw_drivers/lis3mdl/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ cc_library(
srcs = ["lis3mdl.cc"],
hdrs = ["lis3mdl.h"],
visibility = [
"//apps/sbr:__subpackages__",
"//hw_services/sbr:__subpackages__",
],
deps = [
Expand Down

0 comments on commit e0b6b35

Please sign in to comment.