Import of the watch repository from Pebble

This commit is contained in:
Matthieu Jeanson 2024-12-12 16:43:03 -08:00 committed by Katharine Berry
commit 3b92768480
10334 changed files with 2564465 additions and 0 deletions

View file

@ -0,0 +1,65 @@
/*
* Copyright 2024 Google LLC
*
* 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
*
* http://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 "mfg_factory_mode.h"
#include "apps/prf_apps/mfg_menu_app.h"
#include "board/board.h"
#include "kernel/event_loop.h"
#include "kernel/low_power.h"
#include "process_management/app_manager.h"
#include "services/prf/accessory/accessory_manager.h"
#include "services/prf/idle_watchdog.h"
static bool s_mfg_mode = false;
static void prv_launch_mfg_app(void *data) {
// Make sure we can launch our MFG app and subsequent apps.
app_manager_set_minimum_run_level(ProcessAppRunLevelNormal);
app_manager_launch_new_app(&(AppLaunchConfig) {
.md = mfg_menu_app_get_info(),
});
}
void mfg_enter_mfg_mode(void) {
if (!s_mfg_mode) {
s_mfg_mode = true;
#if CAPABILITY_HAS_ACCESSORY_CONNECTOR
accessory_manager_set_state(AccessoryInputStateMfg);
#endif
prf_idle_watchdog_stop();
low_power_exit();
}
}
void mfg_enter_mfg_mode_and_launch_app(void) {
if (!s_mfg_mode) {
mfg_enter_mfg_mode();
launcher_task_add_callback(prv_launch_mfg_app, NULL);
}
}
bool mfg_is_mfg_mode(void) {
return s_mfg_mode;
}
void command_enter_mfg(void) {
mfg_enter_mfg_mode_and_launch_app();
}

View file

@ -0,0 +1,28 @@
/*
* Copyright 2024 Google LLC
*
* 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
*
* http://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.
*/
#pragma once
#include <stdbool.h>
//! Enter manufacturing mode, but does not start the manufacturing app.
void mfg_enter_mfg_mode(void);
//! Enter manufacturing mode and also add a launcher task callback to start the MFG Menu App.
void mfg_enter_mfg_mode_and_launch_app(void);
bool mfg_is_mfg_mode(void);

View file

@ -0,0 +1,110 @@
/*
* Copyright 2024 Google LLC
*
* 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
*
* http://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 "bluetooth/bt_test.h"
#include "console/prompt.h"
#include "drivers/button.h"
#include "drivers/flash.h"
#include "drivers/i2c.h"
#include "drivers/imu.h"
#include "drivers/imu/bmi160/bmi160.h"
#include "util/bitset.h"
#include "util/size.h"
#include <string.h>
#include <stdbool.h>
#include <inttypes.h>
struct SelfTestCase {
char name[16];
bool (*func)(void);
};
// TODO: PBL-34018 This file is a mess. We should clean it up to better chose the right functions
// and list of test cases depending on the capabilities of the platform.
// Here's a clever trick: selftest functions which may or may not be
// linked into the firmware depending on the ./waf configure settings
// (read: IMU) are redeclared as weak so that it is not a linker error
// to have missing definitions for these functions. They simply link as
// zero (null pointer). This works out perfectly as the selftest code
// considers a null function pointer to mean not-implemented, which is
// exactly the outcome we want!
bool bmi160_query_whoami(void) WEAK;
bool bma255_query_whoami(void) WEAK;
bool flash_check_whoami(void) WEAK;
bool accel_manager_run_selftest(void) WEAK;
bool gyro_manager_run_selftest(void) WEAK;
bool mag3110_check_whoami(void) WEAK;
bool snowy_mag3110_query_whoami(void) WEAK;
// NULL function pointer means test is not implemented
static const struct SelfTestCase s_test_cases[] = {
#if PLATFORM_SILK
{ "Accel Comm", bma255_query_whoami },
#else
{ "IMU Comm", bmi160_query_whoami },
#endif
{ "Accel ST", accel_manager_run_selftest },
#if !PLATFORM_SILK
{ "Gyro ST", gyro_manager_run_selftest },
{ "MAG3110 Comm", mag3110_check_whoami },
#endif
#if CAPABILITY_HAS_APPLE_MFI
{ "Apple ACP I2C", bt_driver_test_mfi_chip_selftest },
#endif
{ "BT Module", bt_driver_test_selftest },
{ "Flash Comm", flash_check_whoami },
{ "Buttons", button_selftest },
};
static char* bool_to_pass_fail(bool b) {
if (b) {
return "PASS";
} else {
return "FAIL";
}
}
//! Runs all the test cases
//! @return a bitset of tests that passed or failed
uint32_t mfg_selftest(void) {
uint32_t result = 0;
for (uint32_t i = 0; i < ARRAY_LENGTH(s_test_cases); i++) {
const struct SelfTestCase* test = s_test_cases + i;
bool test_passed = false;
if (test->func != 0) {
test_passed = test->func();
}
bitset32_update(&result, i, test_passed);
}
return result;
}
void command_selftest(void) {
char buffer[32];
uint32_t result = mfg_selftest();
for (uint32_t i = 0; i < ARRAY_LENGTH(s_test_cases); i++) {
const struct SelfTestCase* test = s_test_cases + i;
char *pass_fail;
if (test->func != 0) { // Test is implemented
pass_fail = bool_to_pass_fail(bitset32_get(&result, i));
} else {
pass_fail = "NYI";
}
prompt_send_response_fmt(buffer, 32, "%15s: %s", test->name, pass_fail);
}
}