<commit_before>/* Copyright 2021 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

/**
 * @file
 *
 * @brief Backend API for Smart Battery emulator
 */

#ifndef __EMUL_SMART_BATTERY_H
#define __EMUL_SMART_BATTERY_H

#include <zephyr/drivers/emul.h>
#include <zephyr/drivers/i2c.h>
#include <zephyr/drivers/i2c_emul.h>
#include <stdint.h>

/**
 * @brief Smart Battery emulator backend API
 * @defgroup sbat_emul Smart Battery emulator
 * @{
 *
 * Smart Battery emulator handle static state of device. E.g. setting charging
 * current will not charge battery over time. Sending periodic status messages
 * and alarms to SMBus Host or charging voltage/current to Smart Battery Charger
 * is not supported. Behaviour of Smart Battery emulator is application-defined.
 * As-such, each application may
 *
 * - define a Device Tree overlay file to set the most of battery properties
 * - get battery properties calling @ref sbat_emul_get_bat_data Battery
 *   properties can be changed through obtained pointer. In multithread
 *   environment access to battery can be guarded by calling
 *   @ref sbat_emul_lock_bat_data and @ref sbat_emul_unlock_bat_data
 * - call functions from emul_common_i2c.h to setup custom handlers for SMBus
 *   messages
 */

/* Value used to indicate that no command is selected */
#define SBAT_EMUL_NO_CMD	-1
/* Maximum size of data that can be returned in SMBus block transaction */
#define MAX_BLOCK_SIZE		32
/* Maximum length of command to send is maximum size of data + len byte + PEC */
#define MSG_BUF_LEN		(MAX_BLOCK_SIZE + 2)

/** @brief Emulated smart battery properties */
struct sbat_emul_bat_data {
	/** Battery mode - bit field configuring some battery behaviours */
	uint16_t mode;
	/** Word returned on manufacturer access command */
	uint16_t mf_access;
	/** Capacity alarm value */
	uint16_t cap_alarm;
	/** Remaing time alarm value */
	uint16_t time_alarm;
	/** Rate of charge used in some commands */
	int16_t at_rate;
	/**
	 * Flag indicating if AT_RATE_TIME_TO_FULL command supports mW
	 * capacity mode
	 */
	int at_rate_full_mw_support;
	/** Error code returned by last command */
	uint16_t error_code;
	/** Design battery voltage in mV */
	uint16_t design_mv;
	/** Battery temperature at the moment in Kelvins */
	uint16_t temp;<commit_msg>zephyr/include/emul/emul_smart_battery.h: Format with clang-format<commit_after>/* Copyright 2021 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

/**
 * @file
 *
 * @brief Backend API for Smart Battery emulator
 */

#ifndef __EMUL_SMART_BATTERY_H
#define __EMUL_SMART_BATTERY_H

#include <zephyr/drivers/emul.h>
#include <zephyr/drivers/i2c.h>
#include <zephyr/drivers/i2c_emul.h>
#include <stdint.h>

/**
 * @brief Smart Battery emulator backend API
 * @defgroup sbat_emul Smart Battery emulator
 * @{
 *
 * Smart Battery emulator handle static state of device. E.g. setting charging
 * current will not charge battery over time. Sending periodic status messages
 * and alarms to SMBus Host or charging voltage/current to Smart Battery Charger
 * is not supported. Behaviour of Smart Battery emulator is application-defined.
 * As-such, each application may
 *
 * - define a Device Tree overlay file to set the most of battery properties
 * - get battery properties calling @ref sbat_emul_get_bat_data Battery
 *   properties can be changed through obtained pointer. In multithread
 *   environment access to battery can be guarded by calling
 *   @ref sbat_emul_lock_bat_data and @ref sbat_emul_unlock_bat_data
 * - call functions from emul_common_i2c.h to setup custom handlers for SMBus
 *   messages
 */

/* Value used to indicate that no command is selected */
#define SBAT_EMUL_NO_CMD -1
/* Maximum size of data that can be returned in SMBus block transaction */
#define MAX_BLOCK_SIZE 32
/* Maximum length of command to send is maximum size of data + len byte + PEC */
#define MSG_BUF_LEN (MAX_BLOCK_SIZE + 2)

/** @brief Emulated smart battery properties */
struct sbat_emul_bat_data {
	/** Battery mode - bit field configuring some battery behaviours */
	uint16_t mode;
	/** Word returned on manufacturer access command */
	uint16_t mf_access;
	/** Capacity alarm value */
	uint16_t cap_alarm;
	/** Remaing time alarm value */
	uint16_t time_alarm;
	/** Rate of charge used in some commands */
	int16_t at_rate;
	/**
	 * Flag indicating if AT_RATE_TIME_TO_FULL command supports mW
	 * capacity mode
	 */
	int at_rate_full_mw_support;
	/** Error code returned by last command */
	uint16_t error_code;
	/** Design battery voltage in mV */
	uint16_t design_mv;
	/** Battery temperature at the moment in Kelvins */
	uint16_t temp;
{'fraction_non_alphanumeric': 0.07404343329886245, 'fraction_numerical': 0.011168562564632886, 'mean_word_length': 4.032258064516129, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5383015', 'n_tokens_mistral': 1561, 'n_tokens_neox': 1470, 'n_words': 576}