未验证 提交 a1e43a27 编写于 作者: O openharmony_ci 提交者: Gitee

!23103 【3.2-Release】翻译完成 22121+22163+21648+21697+21405+21595+21548+21581+22066+22034+22115+21529

Merge pull request !23103 from ester.zhou/C2-22121
...@@ -12,7 +12,7 @@ For details about the APIs, see [API Reference](../reference/apis/js-apis-common ...@@ -12,7 +12,7 @@ For details about the APIs, see [API Reference](../reference/apis/js-apis-common
| API| Description| | API| Description|
| -------- | -------- | | -------- | -------- |
| createSubscriber(subscribeInfo: [CommonEventSubscribeInfo](../reference/apis/js-apis-commonEventManager.md#commoneventsubscribeinfo), callback: AsyncCallback<[CommonEventData](../reference/apis/js-apis-commonEventManager.md#commoneventdata)>): void | Creates a subscriber. This API uses an asynchronous callback to return the result.| | createSubscriber(subscribeInfo: [CommonEventSubscribeInfo](../reference/apis/js-apis-commonEventManager.md#commoneventsubscribeinfo), callback: AsyncCallback<[CommonEventSubscriber](../reference/apis/js-apis-inner-commonEvent-commonEventSubscriber.md#usage)>): void | Creates a subscriber. This API uses an asynchronous callback to return the result.|
| createSubscriber(subscribeInfo: CommonEventSubscribeInfo): Promise<CommonEventSubscriber> | Creates a subscriber. This API uses a promise to return the result.| | createSubscriber(subscribeInfo: CommonEventSubscribeInfo): Promise<CommonEventSubscriber> | Creates a subscriber. This API uses a promise to return the result.|
| subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback): void | Subscribes to common events.| | subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback): void | Subscribes to common events.|
......
# Creating a Custom Component # Creating a Custom Component
In ArkUI, components are what's displayed on the UI. They can be classified as built-in components – those directly provided by ArkUI framework, and custom components – those defined by developers. Defining the entire application UI with just built-in components would lead to a monolithic design, low code maintainability, and poor execution performance. A good UI is the result of a well-thought-out development process, with such factors as code reusability, separation of service logic from the UI, and version evolution carefully considered. Creating custom components that encapsulate the UI and some business logic is a critical step in this process. In ArkUI, components are what's displayed on the UI. They can be classified as built-in components – those directly provided by the ArkUI framework, and custom components – those defined by developers. Defining the entire application UI with just built-in components would lead to a monolithic design, low code maintainability, and poor execution performance. A good UI is the result of a well-thought-out development process, with such factors as code reusability, separation of service logic from the UI, and version evolution carefully considered. Creating custom components that encapsulate the UI and some business logic is a critical step in this process.
The custom component has the following features: The custom component has the following features:
...@@ -62,7 +62,7 @@ To fully understand the preceding example, a knowledge of the following concepts ...@@ -62,7 +62,7 @@ To fully understand the preceding example, a knowledge of the following concepts
- [Basic Structure of a Custom Component](#basic-structure-of-a-custom-component) - [Basic Structure of a Custom Component](#basic-structure-of-a-custom-component)
- [Member Functions/Variables](#member-functionsvariables) - Member functions/Variables
- [Rules of for Custom Component Parameters](#rules-of-for-custom-component-parameters) - [Rules of for Custom Component Parameters](#rules-of-for-custom-component-parameters)
...@@ -70,7 +70,6 @@ To fully understand the preceding example, a knowledge of the following concepts ...@@ -70,7 +70,6 @@ To fully understand the preceding example, a knowledge of the following concepts
- [Universal Style of a Custom Component](#universal-style-of-a-custom-component) - [Universal Style of a Custom Component](#universal-style-of-a-custom-component)
- [Custom Attribute Methods](#custom-attribute-methods)
## Basic Structure of a Custom Component ## Basic Structure of a Custom Component
...@@ -80,7 +79,7 @@ To fully understand the preceding example, a knowledge of the following concepts ...@@ -80,7 +79,7 @@ To fully understand the preceding example, a knowledge of the following concepts
> >
> The name or its class or function name of a custom component must be different from that of any built-in components. > The name or its class or function name of a custom component must be different from that of any built-in components.
- \@Component: The \@Component decorator can decorate only the data structures declared by the **struct** keyword. After being decorated by \@Component, a struct has the componentization capability. It must implement the **build** function to describe the UI. One struct can be decorated by only one \@Component. - \@Component: The \@Component decorator can decorate only the structs declared by the **struct** keyword. After being decorated by \@Component, a struct has the componentization capability. It must implement the **build** function to describe the UI. One struct can be decorated by only one \@Component.
> **NOTE** > **NOTE**
> >
> Since API version 9, this decorator is supported in ArkTS widgets. > Since API version 9, this decorator is supported in ArkTS widgets.
...@@ -314,67 +313,3 @@ struct MyComponent { ...@@ -314,67 +313,3 @@ struct MyComponent {
> **NOTE** > **NOTE**
> >
> When ArkUI sets styles for custom components, an invisible container component is set for **MyComponent2**. These styles are set on the container component instead of the **\<Button>** component of **MyComponent2**. As seen from the rendering result, the red background color is not directly applied to the button. Instead, it is applied to the container component that is invisible to users where the button is located. > When ArkUI sets styles for custom components, an invisible container component is set for **MyComponent2**. These styles are set on the container component instead of the **\<Button>** component of **MyComponent2**. As seen from the rendering result, the red background color is not directly applied to the button. Instead, it is applied to the container component that is invisible to users where the button is located.
## Custom Attribute Methods
Custom components do not support custom attribute methods. You can use the Controller capability to implement custom APIs.
```ts
// Custom controller
export class MyComponentController {
item: MyComponent = null;
setItem(item: MyComponent) {
this.item = item;
}
changeText(value: string) {
this.item.value = value;
}
}
// Custom component
@Component
export default struct MyComponent {
public controller: MyComponentController = null;
@State value: string = 'Hello World';
build() {
Column() {
Text(this.value)
.fontSize(50)
}
}
aboutToAppear() {
if (this.controller)
this.controller.setItem (this); // Link to the controller.
}
}
// Processing logic
@Entry
@Component
struct StyleExample {
controller = new MyComponentController();
build() {
Column() {
MyComponent({ controller: this.controller })
}
.onClick(() => {
this.controller.changeText('Text');
})
}
}
```
In the preceding example:
1. The **aboutToAppear** method of the **MyComponent** child component passes the current **this** pointer to the **item** member variable of **MyComponentController**.
2. The **StyleExample** parent component holds a **Controller** instance and with which calls the **changeText** API of **Controller**. That is, the value of the state variable **value** of **MyComponent** is changed through the **this** pointer of the **MyComponent** child component held by the controller.
Through the encapsulation of the controller, **MyComponent** exposes the **changeText** API. All instances that hold the controller can call the **changeText** API to change the value of the **MyComponent** state variable **value**.
...@@ -15,12 +15,11 @@ Environment is a singleton object created by the ArkUI framework at application ...@@ -15,12 +15,11 @@ Environment is a singleton object created by the ArkUI framework at application
- Use **Environment.EnvProp** to save the environment variables of the device to AppStorage. - Use **Environment.EnvProp** to save the environment variables of the device to AppStorage.
```ts ```ts
// Save the language code of the device to AppStorage. The default value is en. // Save languageCode to AppStorage. The default value is en.
// Whenever its value changes in the device environment, it will update its value in AppStorage.
Environment.EnvProp('languageCode', 'en'); Environment.EnvProp('languageCode', 'en');
``` ```
- To keep a component variable updated with changes in the device environment, this variable should be decorated with \@StorageProp. - Decorate the variables with \@StorageProp to link them with components.
```ts ```ts
@StorageProp('languageCode') lang : string = 'en'; @StorageProp('languageCode') lang : string = 'en';
......
...@@ -367,7 +367,7 @@ The **extensionAbilities** tag represents the configuration of extensionAbilitie ...@@ -367,7 +367,7 @@ The **extensionAbilities** tag represents the configuration of extensionAbilitie
| icon | Icon of the ExtensionAbility component. The value is an icon resource index. If **ExtensionAbility** is set to **MainElement** of the current module, this attribute is mandatory and its value must be unique in the application.| String| Yes (initial value: left empty)| | icon | Icon of the ExtensionAbility component. The value is an icon resource index. If **ExtensionAbility** is set to **MainElement** of the current module, this attribute is mandatory and its value must be unique in the application.| String| Yes (initial value: left empty)|
| label | Name of the ExtensionAbility component displayed to users. The value is a string resource index.<br>**NOTE**<br>If **ExtensionAbility** is set to **MainElement** of the current module, this attribute is mandatory and its value must be unique in the application.| String| No| | label | Name of the ExtensionAbility component displayed to users. The value is a string resource index.<br>**NOTE**<br>If **ExtensionAbility** is set to **MainElement** of the current module, this attribute is mandatory and its value must be unique in the application.| String| No|
| type | Type of the ExtensionAbility component. The options are as follows:<br>- **form**: ExtensionAbility of a widget.<br>- **workScheduler**: ExtensionAbility of a Work Scheduler task.<br>- **inputMethod**: ExtensionAbility of an input method.<br>- **service**: service component running in the background.<br>- **accessibility**: ExtensionAbility of an accessibility feature.<br>- **dataShare**: ExtensionAbility for data sharing.<br>- **fileShare**: ExtensionAbility for file sharing.<br>- **staticSubscriber**: ExtensionAbility for static broadcast.<br>- **wallpaper**: ExtensionAbility of the wallpaper.<br>- **backup**: ExtensionAbility for data backup.<br>- **window**: ExtensionAbility of a window. This type of ExtensionAbility creates a window during startup for which you can develop the GUI. The window is then combined with other application windows through **abilityComponent**.<br>- **thumbnail**: ExtensionAbility for obtaining file thumbnails. You can provide thumbnails for files of customized file types.<br>- **preview**: ExtensionAbility for preview. This type of ExtensionAbility can parse the file and display it in a window. You can combine the window with other application windows.<br>**NOTE**<br>The **service** and **dataShare** types apply only to system applications and do not take effect for third-party applications. | String| No| | type | Type of the ExtensionAbility component. The options are as follows:<br>- **form**: ExtensionAbility of a widget.<br>- **workScheduler**: ExtensionAbility of a Work Scheduler task.<br>- **inputMethod**: ExtensionAbility of an input method.<br>- **service**: service component running in the background.<br>- **accessibility**: ExtensionAbility of an accessibility feature.<br>- **dataShare**: ExtensionAbility for data sharing.<br>- **fileShare**: ExtensionAbility for file sharing.<br>- **staticSubscriber**: ExtensionAbility for static broadcast.<br>- **wallpaper**: ExtensionAbility of the wallpaper.<br>- **backup**: ExtensionAbility for data backup.<br>- **window**: ExtensionAbility of a window. This type of ExtensionAbility creates a window during startup for which you can develop the GUI. The window is then combined with other application windows through **abilityComponent**.<br>- **thumbnail**: ExtensionAbility for obtaining file thumbnails. You can provide thumbnails for files of customized file types.<br>- **preview**: ExtensionAbility for preview. This type of ExtensionAbility can parse the file and display it in a window. You can combine the window with other application windows.<br>**NOTE**<br>The **service** and **dataShare** types apply only to system applications and do not take effect for third-party applications. | String| No|
| permissions | Permissions required for another application to access the ExtensionAbility component.<br>The value is generally in the reverse domain name notation and contains a maximum of 255 bytes. It is an array of permission names predefined by the system or customized. The name of a customized permission must be the same as the **name** value of a permission defined in the **defPermissions** attribute.| String array| Yes (initial value: left empty)| | permissions | Permissions required for another application to access the ExtensionAbility component.<br>The value is generally in the reverse domain name notation and contains a maximum of 255 bytes. It is an array of [predefined permission names](../security/permission-list.md).| String array| Yes (initial value: left empty)|
| uri | Data URI provided by the ExtensionAbility component. The value is a string with a maximum of 255 bytes, in the reverse domain name notation.<br>**NOTE**<br>This attribute is mandatory when the type of the ExtensionAbility component is set to **dataShare**.| String| Yes (initial value: left empty)| | uri | Data URI provided by the ExtensionAbility component. The value is a string with a maximum of 255 bytes, in the reverse domain name notation.<br>**NOTE**<br>This attribute is mandatory when the type of the ExtensionAbility component is set to **dataShare**.| String| Yes (initial value: left empty)|
|skills | Feature set of [wants](../application-models/want-overview.md) that can be received by the ExtensionAbility component.<br>Configuration rule: In an entry package, you can configure multiple **skills** attributes with the entry capability. (A **skills** attribute with the entry capability is the one that has **ohos.want.action.home** and **entity.system.home** configured.) The **label** and **icon** in the first ExtensionAbility that has **skills** configured are used as the **label** and **icon** of the entire OpenHarmony service/application.<br>**NOTE**<br>The **skills** attribute with the entry capability can be configured for the feature package of an OpenHarmony application, but not for an OpenHarmony service.| Array| Yes (initial value: left empty)| |skills | Feature set of [wants](../application-models/want-overview.md) that can be received by the ExtensionAbility component.<br>Configuration rule: In an entry package, you can configure multiple **skills** attributes with the entry capability. (A **skills** attribute with the entry capability is the one that has **ohos.want.action.home** and **entity.system.home** configured.) The **label** and **icon** in the first ExtensionAbility that has **skills** configured are used as the **label** and **icon** of the entire OpenHarmony service/application.<br>**NOTE**<br>The **skills** attribute with the entry capability can be configured for the feature package of an OpenHarmony application, but not for an OpenHarmony service.| Array| Yes (initial value: left empty)|
| [metadata](#metadata)| Metadata of the ExtensionAbility component.| Object| Yes (initial value: left empty)| | [metadata](#metadata)| Metadata of the ExtensionAbility component.| Object| Yes (initial value: left empty)|
......
...@@ -36,8 +36,8 @@ Defines the initialization options for **createTimer**. ...@@ -36,8 +36,8 @@ Defines the initialization options for **createTimer**.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ | | --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| type | number | Yes | Timer type.<br>**1**: CPU time type. (The start time of the timer cannot be later than the current system time.)<br>**2**: wakeup type.<br>**4**: exact type.<br>**8**: idle type (not supported currently).| | type | number | Yes | Timer type.<br>**1**: CPU time type. (The start time of the timer cannot be later than the current system time.)<br>**2**: wakeup type.<br>**4**: exact type.<br>**8**: idle type (not supported currently).|
| repeat | boolean | Yes | Whether the timer is a repeating timer. The value **true** means that the timer is a repeating timer, and **false** means that the timer is a one-shot timer. | | repeat | boolean | Yes | Whether the timer is a repeating timer.<br>The value **true** means that the timer is a repeating timer, and **false** means that the timer is a one-shot timer. |
| interval | number | No | Repeat interval. For a repeating timer, the value must be greater than 5000 ms. For a one-shot timer, the value is **0**.| | interval | number | No | Repeat interval.<br>For a repeating timer, the value must be greater than 5000 ms. For a one-shot timer, the value is **0**.|
| wantAgent | [WantAgent](js-apis-app-ability-wantAgent.md) | No | **WantAgent** object of the notification to be sent when the timer expires. (An application MainAbility can be started, but not a Service ability.)| | wantAgent | [WantAgent](js-apis-app-ability-wantAgent.md) | No | **WantAgent** object of the notification to be sent when the timer expires. (An application MainAbility can be started, but not a Service ability.)|
| callback | number | Yes | Callback used to return the timer ID. | | callback | number | Yes | Callback used to return the timer ID. |
......
...@@ -3326,6 +3326,10 @@ struct WebComponent { ...@@ -3326,6 +3326,10 @@ struct WebComponent {
Implements a **WebCookieManager** instance to manage behavior of cookies in **\<Web>** components. All **\<Web>** components in an application share a **WebCookieManager** instance. Implements a **WebCookieManager** instance to manage behavior of cookies in **\<Web>** components. All **\<Web>** components in an application share a **WebCookieManager** instance.
> **NOTE**
>
> You must load the **\<Web>** component before calling APIs in **WebCookieManager**.
### getCookie ### getCookie
static getCookie(url: string): string static getCookie(url: string): string
...@@ -3788,6 +3792,10 @@ struct WebComponent { ...@@ -3788,6 +3792,10 @@ struct WebComponent {
Implements a **WebStorage** object to manage the Web SQL database and HTML5 Web Storage APIs. All **\<Web>** components in an application share a **WebStorage** object. Implements a **WebStorage** object to manage the Web SQL database and HTML5 Web Storage APIs. All **\<Web>** components in an application share a **WebStorage** object.
> **NOTE**
>
> You must load the **\<Web>** component before calling the APIs in **WebStorage**.
### deleteOrigin ### deleteOrigin
static deleteOrigin(origin : string): void static deleteOrigin(origin : string): void
...@@ -4248,6 +4256,10 @@ struct WebComponent { ...@@ -4248,6 +4256,10 @@ struct WebComponent {
Implements a **WebDataBase** object. Implements a **WebDataBase** object.
> **NOTE**
>
> You must load the **\<Web>** component before calling the APIs in **WebDataBase**.
### getHttpAuthCredentials ### getHttpAuthCredentials
static getHttpAuthCredentials(host: string, realm: string): Array\<string> static getHttpAuthCredentials(host: string, realm: string): Array\<string>
...@@ -4426,6 +4438,10 @@ struct WebComponent { ...@@ -4426,6 +4438,10 @@ struct WebComponent {
Implements a **GeolocationPermissions** object. Implements a **GeolocationPermissions** object.
> **NOTE**
>
> You must load the **\<Web>** component before calling the APIs in **GeolocationPermissions**.
### Required Permissions ### Required Permissions
**ohos.permission.LOCATION**, **ohos.permission.APPROXIMATELY_LOCATION**, and **ohos.permission.LOCATION_IN_BACKGROUND**, which are required for accessing the location information. For details about the permissions, see [@ohos.geolocation (Geolocation)](./js-apis-geolocation.md). **ohos.permission.LOCATION**, **ohos.permission.APPROXIMATELY_LOCATION**, and **ohos.permission.LOCATION_IN_BACKGROUND**, which are required for accessing the location information. For details about the permissions, see [@ohos.geolocation (Geolocation)](./js-apis-geolocation.md).
......
...@@ -165,7 +165,7 @@ Not supported ...@@ -165,7 +165,7 @@ Not supported
strokeColor: '#0081ff', strokeColor: '#0081ff',
fillColor: '#cce5ff', fillColor: '#cce5ff',
data: [763, 550, 551, 554, 731, 654, 525, 696, 595, 628, 791, 505, 613, 575, 475, 553, 491, 680, 657, 716], data: [763, 550, 551, 554, 731, 654, 525, 696, 595, 628, 791, 505, 613, 575, 475, 553, 491, 680, 657, 716],
gradient: true, gradient: false,
} }
], ],
lineOps: { lineOps: {
......
...@@ -28,9 +28,9 @@ Not supported ...@@ -28,9 +28,9 @@ Not supported
| Name| Parameter| Description| | Name| Parameter| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| click | - | Triggered when the component is clicked. | | click | - | Triggered when the component is clicked.|
| longpress | - | Triggered when the component is long pressed. | | longpress | - | Triggered when the component is long pressed.|
| swipe<sup>5+</sup> | [SwipeEvent](js-common-events.md) | Triggered when a user quickly swipes on the component. | | swipe<sup>5+</sup> | [SwipeEvent](js-common-events.md) | Triggered when a user quickly swipes on the component.|
## Styles ## Styles
...@@ -39,8 +39,8 @@ Not supported ...@@ -39,8 +39,8 @@ Not supported
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| color | &lt;color&gt; | \#000000 | No| Color of the QR code.| | color | &lt;color&gt; | \#000000 | No| Color of the QR code.|
| background-color | &lt;color&gt; | \#ffffff | No| Background color of the QR code.| | background-color | &lt;color&gt; | \#ffffff | No| Background color of the QR code.|
| width | &lt;length&gt; \| &lt;percentage&gt;<sup>5+</sup> | - | No| Component width.<br>If this attribute is not set, the default value **0** is used. | | width | &lt;length&gt; \| &lt;percentage&gt;<sup>5+</sup> | - | No| Component width.<br>If this attribute is not set, the default value **0** is used.|
| height | &lt;length&gt; \| &lt;percentage&gt;<sup>5+</sup> | - | No| Component height.<br>If this attribute is not set, the default value **0** is used. | | height | &lt;length&gt; \| &lt;percentage&gt;<sup>5+</sup> | - | No| Component height.<br>If this attribute is not set, the default value **0** is used.|
| padding | &lt;length&gt; | 0 | No| Shorthand attribute to set the padding for all sides.<br>The attribute can have one to four values:<br>- If you set only one value, it specifies the padding for all the four sides.<br>- If you set two values, the first value specifies the top and bottom padding, and the second value specifies the left and right padding.<br>- If you set three values, the first value specifies the top padding, the second value specifies the left and right padding, and the third value specifies the bottom padding.<br>- If you set four values, they respectively specify the padding for top, right, bottom, and left sides (in clockwise order).| | padding | &lt;length&gt; | 0 | No| Shorthand attribute to set the padding for all sides.<br>The attribute can have one to four values:<br>- If you set only one value, it specifies the padding for all the four sides.<br>- If you set two values, the first value specifies the top and bottom padding, and the second value specifies the left and right padding.<br>- If you set three values, the first value specifies the top padding, the second value specifies the left and right padding, and the third value specifies the bottom padding.<br>- If you set four values, they respectively specify the padding for top, right, bottom, and left sides (in clockwise order).|
| padding-[left\|top\|right\|bottom] | &lt;length&gt; | 0 | No| Left, top, right, and bottom padding.| | padding-[left\|top\|right\|bottom] | &lt;length&gt; | 0 | No| Left, top, right, and bottom padding.|
| margin | &lt;length&gt; \| &lt;percentage&gt;<sup>5+</sup> | 0 | No| Shorthand attribute to set the margin for all sides. The attribute can have one to four values:<br>- If you set only one value, it specifies the margin for all the four sides.<br>- If you set two values, the first value specifies the top and bottom margins, and the second value specifies the left and right margins.<br>- If you set three values, the first value specifies the top margin, the second value specifies the left and right margins, and the third value specifies the bottom margin.<br>- If you set four values, they respectively specify the margin for top, right, bottom, and left sides (in clockwise order).| | margin | &lt;length&gt; \| &lt;percentage&gt;<sup>5+</sup> | 0 | No| Shorthand attribute to set the margin for all sides. The attribute can have one to four values:<br>- If you set only one value, it specifies the margin for all the four sides.<br>- If you set two values, the first value specifies the top and bottom margins, and the second value specifies the left and right margins.<br>- If you set three values, the first value specifies the top margin, the second value specifies the left and right margins, and the third value specifies the bottom margin.<br>- If you set four values, they respectively specify the margin for top, right, bottom, and left sides (in clockwise order).|
...@@ -49,7 +49,7 @@ Not supported ...@@ -49,7 +49,7 @@ Not supported
| border-color | &lt;color&gt; | black | No| Shorthand attribute to set the color for all borders.| | border-color | &lt;color&gt; | black | No| Shorthand attribute to set the color for all borders.|
| border-radius | &lt;length&gt; | - | No| Radius of round-corner borders.| | border-radius | &lt;length&gt; | - | No| Radius of round-corner borders.|
| display | string | flex | No| How and whether to display the box containing an element. Available values are as follows:<br>- **flex**: flexible layout<br>- **none**: not rendered| | display | string | flex | No| How and whether to display the box containing an element. Available values are as follows:<br>- **flex**: flexible layout<br>- **none**: not rendered|
| [left\|top] | &lt;length&gt; \| &lt;percentage&gt;<sup>6+</sup> | - | No| Edge of the element.<br>- **left**: left edge position of the element. This attribute defines the offset between the left edge of the margin area of a positioned element and left edge of its containing block.<br>- **top**: top edge position of the element. This attribute defines the offset between the top edge of a positioned element and that of a block included in the element. | | [left\|top] | &lt;length&gt; \| &lt;percentage&gt;<sup>6+</sup> | - | No| Edge of the element.<br>- **left**: left edge position of the element. This attribute defines the offset between the left edge of the margin area of a positioned element and left edge of its containing block.<br>- **top**: top edge position of the element. This attribute defines the offset between the top edge of a positioned element and that of a block included in the element.|
> **NOTE** > **NOTE**
> - If the values of **width** and **height** are different, the smaller value is used as the length of the QR code. The generated QR code is center displayed. > - If the values of **width** and **height** are different, the smaller value is used as the length of the QR code. The generated QR code is center displayed.
...@@ -63,10 +63,10 @@ Not supported ...@@ -63,10 +63,10 @@ Not supported
```html ```html
<!-- xxx.hml --> <!-- xxx.hml -->
<div class="container"> <div class="container">
<qrcode value="{{qr_value}}" class="qrCode" style="color: {{qr_color}};background-color: {{qr_bcol}};"></qrcode> <qrcode value="{{qr_value}}" class="qrCode" style="color: {{qr_col}};background-color: {{qr_bcol}};"></qrcode>
<input type="button" onclick="changeColor" class="button">Color</input> <input type="button" onclick="changeColor" class="button">Color</input>
<input type="button" onclick="changeBackgroundColor" class="button">BackgroundColor</input> <input type="button" onclick="changeBackgroundColor" class="button">BackgroundColor</input>
<input type="button" onclick="changeColor" class="button">Value</input> <input type="button" onclick="changeValue" class="button">Value</input>
</div> </div>
``` ```
...@@ -93,32 +93,32 @@ Not supported ...@@ -93,32 +93,32 @@ Not supported
```javascript ```javascript
// xxx.js // xxx.js
export default { export default {
data: { data: {
qr_col: '#87ceeb', qr_col: '#87ceeb',
qr_bcol: '#f0ffff', qr_bcol: '#f0ffff',
qr_value: 'value' qr_value: 'value'
}, },
changeColor() { changeColor() {
if (this.qr_col == '#87ceeb') { if (this.qr_col == '#87ceeb') {
this.qr_col = '#fa8072'; this.qr_col = '#fa8072';
} else { } else {
this.qr_col = '#87ceeb'; this.qr_col = '#87ceeb';
}
},
changeBackgroundColor() {
if (this.qr_bcol == '#f0ffff') {
this.qr_bcol = '#ffffe0';
} else {
this.qr_bcol = '#f0ffff';
}
},
changeValue() {
if (this.qr_value == 'value') {
this.qr_value = 'change';
} else {
this.qr_value = 'value';
}
} }
},
changeBackgroundColor() {
if (this.qr_bcol == '#f0ffff') {
this.qr_bcol = '#ffffe0';
} else {
this.qr_bcol = '#f0ffff';
}
},
changeValue() {
if (this.qr_value == 'value') {
this.qr_value = 'change';
} else {
this.qr_value = 'value';
}
}
} }
``` ```
......
...@@ -26,6 +26,11 @@ StepperItem() ...@@ -26,6 +26,11 @@ StepperItem()
| nextLabel | string | Text label of the button on the right. The default value is **Start** for the last page and **Next** for the other pages.| | nextLabel | string | Text label of the button on the right. The default value is **Start** for the last page and **Next** for the other pages.|
| status | [ItemState](#itemstate) | Display status of **nextLabel** in the stepper. Optional.<br>Default value: **ItemState.Normal**| | status | [ItemState](#itemstate) | Display status of **nextLabel** in the stepper. Optional.<br>Default value: **ItemState.Normal**|
> **NOTE**
>
> - The **\<StepperItem>** component does not support setting of the universal width attribute. By default, its width is the same as that of the parent **\<Stepper>** component.
> - The **\<StepperItem>** component does not support setting of the universal height attribute. Its height is the height of the parent **\<Stepper>** component minus the height of the label button.
> - The **\<StepperItem>** component does not support setting of the **aspectRadio** or **constrainSize** attribute, which may affect the length and width.
## ItemState ## ItemState
| Name | Description| | Name | Description|
......
...@@ -38,8 +38,8 @@ In addition to the [universal attributes](ts-universal-attributes-size.md), the ...@@ -38,8 +38,8 @@ In addition to the [universal attributes](ts-universal-attributes-size.md), the
| fullHeight | string \| number | Panel height in the **PanelMode.Full** mode.<br>Default value: main axis height of the panel minus 8 vp<br>**NOTE**<br>This attribute cannot be set in percentage.| | fullHeight | string \| number | Panel height in the **PanelMode.Full** mode.<br>Default value: main axis height of the panel minus 8 vp<br>**NOTE**<br>This attribute cannot be set in percentage.|
| halfHeight | string \| number | Panel height in the **PanelMode.Half** mode.<br>Default value: half of the main axis height of the panel<br>**NOTE**<br>This attribute cannot be set in percentage.| | halfHeight | string \| number | Panel height in the **PanelMode.Half** mode.<br>Default value: half of the main axis height of the panel<br>**NOTE**<br>This attribute cannot be set in percentage.|
| miniHeight | string \| number | Panel height in the **PanelMode.Mini** mode.<br>Default value: **48**<br>Unit: vp<br>**NOTE**<br>This attribute cannot be set in percentage.| | miniHeight | string \| number | Panel height in the **PanelMode.Mini** mode.<br>Default value: **48**<br>Unit: vp<br>**NOTE**<br>This attribute cannot be set in percentage.|
| show | boolean | Whether to show the panel.| | show | boolean | Whether to show the panel.<br>Default value: **true**|
| backgroundMask<sup>9+</sup>|[ResourceColor](ts-types.md#resourcecolor)|Background mask of the panel.| | backgroundMask<sup>9+</sup>|[ResourceColor](ts-types.md#resourcecolor)|Background mask of the panel.<br>Default value: **'#08182431'**|
## PanelType ## PanelType
...@@ -101,4 +101,4 @@ struct PanelExample { ...@@ -101,4 +101,4 @@ struct PanelExample {
} }
``` ```
![en-us_image_0000001256978381](figures/en-us_image_0000001256978381.gif) ![en-us_image_0000001174422896](figures/en-us_image_0000001174422896.gif)
# Device Driver Porting<a name="EN-US_TOPIC_0000001200252097"></a> # Device Driver Porting
This section describes how to port device drivers. This section describes how to port device drivers.
## LCD Driver Porting<a name="section1574513454119"></a> ## LCD Driver Porting
To port an LCD driver, write the driver, create an instance of the corresponding model in the driver, and complete the registration. To port an LCD driver, write the driver, create an instance of the corresponding model in the driver, and complete the registration.
The LCD drivers are stored in **//drivers/framework/model/display/driver/panel**. The LCD drivers are stored in **//drivers/hdf_core/framework/model/display/driver/panel**.
1. Create a panel driver. 1. Create a panel driver.
Create an HDF driver and call the **RegisterPanel** method to register a model instance during driver initialization. Create an HDF driver and call the **RegisterPanel** method to register a model instance during driver initialization.
```
int32_t LCDxxEntryInit(struct HdfDeviceObject *object) ```
{ int32_t LCDxxEntryInit(struct HdfDeviceObject *object)
struct PanelData *panel = CreateYourPanel(); {
// Register a model instance. struct PanelData *panel = CreateYourPanel();
if (RegisterPanel(panel) != HDF_SUCCESS) { // Register a model instance.
HDF_LOGE("%s: RegisterPanel failed", __func__); if (RegisterPanel(panel) != HDF_SUCCESS) {
return HDF_FAILURE; HDF_LOGE("%s: RegisterPanel failed", __func__);
} return HDF_FAILURE;
return HDF_SUCCESS; }
} return HDF_SUCCESS;
}
struct HdfDriverEntry g_xxxxDevEntry = {
.moduleVersion = 1, struct HdfDriverEntry g_xxxxDevEntry = {
.moduleName = "LCD_XXXX", .moduleVersion = 1,
.Init = LCDxxEntryInit, .moduleName = "LCD_XXXX",
}; .Init = LCDxxEntryInit,
};
HDF_INIT(g_xxxxDevEntry);
``` HDF_INIT(g_xxxxDevEntry);
```
2. Configure and load the panel driver. 2. Configure and load the panel driver.
Modify the source code file **//vendor/vendor\_name/product\_name/config/device\_info/device\_info.hcs**. Add configurations for the device named **device\_lcd** for the display host. Modify the source code file **//vendor/vendor_name/product_name/config/device_info/device_info.hcs**. Add configurations for the device named **device\_lcd** for the display host.
>![](../public_sys-resources/icon-caution.gif) **CAUTION:** > ![icon-caution.gif](public_sys-resources/icon-caution.gif) **CAUTION**
>Make sure the value of **moduleName** is the same as that of **moduleName** in the panel driver. > Make sure the value of **moduleName** is the same as that of **moduleName** in the panel driver.
```
root { ```
... root {
display :: host { ...
device_lcd :: device { display :: host {
deviceN :: deviceNode { device_lcd :: device {
policy = 0; deviceN :: deviceNode {
priority = 100; policy = 0;
preload = 2; priority = 100;
moduleName = "LCD_XXXX"; preload = 2;
} moduleName = "LCD_XXXX";
} }
} }
} }
``` }
```
## Touchscreen Driver Porting<a name="section20284142116422"></a> ## Touchscreen Driver Porting
This section describes how to port a touchscreen driver. The touchscreen drivers are stored in the source code directory **//drivers/framework/model/input/driver/touchscreen**. To port a touchscreen driver, register a **ChipDevice** model instance with the system. This section describes how to port a touchscreen driver. The touchscreen drivers are stored in the source code directory **//drivers/hdf_core/framework/model/input/driver/touchscreen**. To port a touchscreen driver, register a **ChipDevice** model instance with the system.
For details about how to develop a touchscreen driver, see [Touchscreen Development Guidelines](../driver/driver-peripherals-touch-des.md). For details about how to develop a touchscreen driver, see [Touchscreen Development Guidelines](../driver/driver-peripherals-touch-des.md).
1. Create a touchscreen driver. 1. Create a touchscreen driver.
Create the **touch\_ic\_name.c** file in the **touchscreen** directory. Write the following content: Create the **touch\_ic\_name.c** file in the **touchscreen** directory. Write the following content:
```
#include "hdf_touch.h" ```
#include "hdf_touch.h"
static int32_t HdfXXXXChipInit(struct HdfDeviceObject *device)
{ static int32_t HdfXXXXChipInit(struct HdfDeviceObject *device)
ChipDevice *tpImpl = CreateXXXXTpImpl(); {
if(RegisterChipDevice(tpImpl) != HDF_SUCCESS) {// Register the ChipDevice model instance. ChipDevice *tpImpl = CreateXXXXTpImpl();
ReleaseXXXXTpImpl(tpImpl); if(RegisterChipDevice(tpImpl) != HDF_SUCCESS) { // Register the ChipDevice model instance.
return HDF_FAILURE; ReleaseXXXXTpImpl(tpImpl);
} return HDF_FAILURE;
return HDF_SUCCESS; }
} return HDF_SUCCESS;
}
struct HdfDriverEntry g_touchXXXXChipEntry = {
.moduleVersion = 1, struct HdfDriverEntry g_touchXXXXChipEntry = {
.moduleName = "HDF_TOUCH_XXXX", // Make sure the value is the same as that in the subsequent configuration. .moduleVersion = 1,
.Init = HdfXXXXChipInit, .moduleName = "HDF_TOUCH_XXXX", // Make sure the value is the same as that in the subsequent configuration.
}; .Init = HdfXXXXChipInit,
};
HDF_INIT(g_touchXXXXChipEntry);
```
The following methods need to be implemented in **ChipDevice**:
HDF_INIT(g_touchXXXXChipEntry); | Method | Description |
``` | -------- | -------- |
| int32_t&nbsp;(\*Init)(ChipDevice&nbsp;\*device) | Initializes the device. |
The following methods need to be implemented in **ChipDevice**: | int32_t&nbsp;(\*Detect)(ChipDevice&nbsp;\*device) | Detects the device. |
| int32_t&nbsp;(\*Suspend)(ChipDevice&nbsp;\*device) | Places the device in sleep mode. |
<a name="table63781245516"></a> | int32_t&nbsp;(\*Resume)(ChipDevice&nbsp;\*device) | Wakes up the device. |
<table><thead align="left"><tr id="row1639713218557"><th class="cellrowborder" valign="top" width="50%" id="mcps1.1.3.1.1"><p id="p53981829557"><a name="p53981829557"></a><a name="p53981829557"></a>Method</p> | int32_t&nbsp;(\*DataHandle)(ChipDevice&nbsp;\*device) | Reads data from the device and writes touch point data to device > driver > frameData. |
</th> | int32_t&nbsp;(\*UpdateFirmware)(ChipDevice&nbsp;\*device) | Updates the firmware. |
<th class="cellrowborder" valign="top" width="50%" id="mcps1.1.3.1.2"><p id="p739811218557"><a name="p739811218557"></a><a name="p739811218557"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row113981214559"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p339813214552"><a name="p339813214552"></a><a name="p339813214552"></a>int32_t (*Init)(ChipDevice *device)</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p1139810214552"><a name="p1139810214552"></a><a name="p1139810214552"></a>Initializes the device.</p>
</td>
</tr>
<tr id="row15398122145511"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p1139820212557"><a name="p1139820212557"></a><a name="p1139820212557"></a>int32_t (*Detect)(ChipDevice *device)</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p939820217555"><a name="p939820217555"></a><a name="p939820217555"></a>Detects the device.</p>
</td>
</tr>
<tr id="row183981216550"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p8398142165517"><a name="p8398142165517"></a><a name="p8398142165517"></a>int32_t (*Suspend)(ChipDevice *device)</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p539815218558"><a name="p539815218558"></a><a name="p539815218558"></a>Places the device in sleep mode.</p>
</td>
</tr>
<tr id="row1239842115519"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p43981295511"><a name="p43981295511"></a><a name="p43981295511"></a>int32_t (*Resume)(ChipDevice *device)</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p173985245515"><a name="p173985245515"></a><a name="p173985245515"></a>Wakes up the device.</p>
</td>
</tr>
<tr id="row5398326559"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p103981324554"><a name="p103981324554"></a><a name="p103981324554"></a>int32_t (*DataHandle)(ChipDevice *device)</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p93980212554"><a name="p93980212554"></a><a name="p93980212554"></a>Reads data from the device and writes touch point data to <strong id="b576475914217"><a name="b576475914217"></a><a name="b576475914217"></a>device</strong> &gt; <strong id="b976511597218"><a name="b976511597218"></a><a name="b976511597218"></a>driver</strong> &gt; <strong id="b117661559162110"><a name="b117661559162110"></a><a name="b117661559162110"></a>frameData</strong>.</p>
</td>
</tr>
<tr id="row03987215550"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p1039814295515"><a name="p1039814295515"></a><a name="p1039814295515"></a>int32_t (*UpdateFirmware)(ChipDevice *device)</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p18398102105520"><a name="p18398102105520"></a><a name="p18398102105520"></a>Updates the firmware.</p>
</td>
</tr>
</tbody>
</table>
2. Configure the product and load the driver. 2. Configure the product and load the driver.
All device information of the product is defined in the source code file **//vendor/vendor\_name/product\_name/config/device\_info/device\_info.hcs**. Modify the file and add configurations to the **device** named **device\_touch\_chip** in the **host** of the **input** command. All device information of the product is defined in the source code file **//vendor/vendor_name/product_name/config/device_info/device_info.hcs**. Modify the file and add configurations to the **device** named **device\_touch\_chip** in the **host** of the **input** command.
>![](../public_sys-resources/icon-note.gif) **NOTE:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
>Make sure the value of **moduleName** is the same as that of **moduleName** in the touchscreen driver. >
> Make sure the value of **moduleName** is the same as that of **moduleName** in the touchscreen driver.
```
deviceN :: deviceNode {
policy = 0;
priority = 130;
preload = 0;
permission = 0660;
moduleName = "HDF_TOUCH_XXXX";
deviceMatchAttr = "touch_XXXX_configs";
}
```
```
deviceN :: deviceNode {
policy = 0;
priority = 130;
preload = 0;
permission = 0660;
moduleName = "HDF_TOUCH_XXXX";
deviceMatchAttr = "touch_XXXX_configs";
}
```
## WLAN Driver Porting<a name="section0969448164217"></a>
## WLAN Driver Porting
The WLAN driver is divided into two parts. One of the parts manages WLAN devices, and the other part manages WLAN traffic. The WLAN driver is divided into two parts. One of the parts manages WLAN devices, and the other part manages WLAN traffic.
**Figure 1** OpenHarmony WLAN driver architecture<a name="fig155920160203"></a> **Figure 1** OpenHarmony WLAN driver architecture<a name="fig155920160203"></a>
![hdf_wifi](figures/hdf_wifi.png)
![](figures/hdf_wifi.png)
As shown in Figure 1, the part on the left manages WLAN devices, and the part on the right manages WLAN traffic. The HDF WLAN framework abstracts these two parts. The porting process of the driver can be considered as the implementation of the APIs required by the two parts. These APIs are described as follows:
As shown in [Figure 1](#fig155920160203), the part on the left manages WLAN devices, and the part on the right manages WLAN traffic. The HDF WLAN framework abstracts these two parts. The porting process of the driver can be considered as the implementation of the APIs required by the two parts. These APIs are described as follows:
| API | Header File | Description |
<a name="table1349145511213"></a> | -------- | -------- | -------- |
<table><thead align="left"><tr id="row867115517211"><th class="cellrowborder" valign="top" width="17.28172817281728%" id="mcps1.1.4.1.1"><p id="p667255120"><a name="p667255120"></a><a name="p667255120"></a>API</p> | HdfChipDriverFactory | drivers\hdf_core\framework\include\wifi\hdf_wlan_chipdriver_manager.h | Factory of the ChipDriver, which is used to support multiple WLAN interfaces of a chip. |
</th> | HdfChipDriver | drivers\hdf_core\framework\include\wifi\wifi_module.h | Manages a specific WLAN interface. |
<th class="cellrowborder" valign="top" width="39.48394839483948%" id="mcps1.1.4.1.2"><p id="p9672551125"><a name="p9672551125"></a><a name="p9672551125"></a>Header File</p> | NetDeviceInterFace | drivers\hdf_core\framework\include\wifi\net_device.h | Communicates with the protocol stack, such as sending data and setting the status of network interfaces. |
</th>
<th class="cellrowborder" valign="top" width="43.23432343234324%" id="mcps1.1.4.1.3"><p id="p166785515214"><a name="p166785515214"></a><a name="p166785515214"></a>API Description</p> > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
</th> >
</tr> > For details about the API development, see [WLAN Development Guidelines](../driver/driver-peripherals-external-des.md).
</thead>
<tbody><tr id="row16671955128"><td class="cellrowborder" valign="top" width="17.28172817281728%" headers="mcps1.1.4.1.1 "><p id="p86712551023"><a name="p86712551023"></a><a name="p86712551023"></a>HdfChipDriverFactory</p>
</td>
<td class="cellrowborder" valign="top" width="39.48394839483948%" headers="mcps1.1.4.1.2 "><p id="p10671551126"><a name="p10671551126"></a><a name="p10671551126"></a>drivers\framework\include\wifi\hdf_wlan_chipdriver_manager.h</p>
</td>
<td class="cellrowborder" valign="top" width="43.23432343234324%" headers="mcps1.1.4.1.3 "><p id="p26725514220"><a name="p26725514220"></a><a name="p26725514220"></a>Factory of the <strong id="b88841282246"><a name="b88841282246"></a><a name="b88841282246"></a>ChipDriver</strong>, which is used to support multiple WLAN interfaces of a chip.</p>
</td>
</tr>
<tr id="row186810552214"><td class="cellrowborder" valign="top" width="17.28172817281728%" headers="mcps1.1.4.1.1 "><p id="p11686551323"><a name="p11686551323"></a><a name="p11686551323"></a>HdfChipDriver</p>
</td>
<td class="cellrowborder" valign="top" width="39.48394839483948%" headers="mcps1.1.4.1.2 "><p id="p11686551723"><a name="p11686551723"></a><a name="p11686551723"></a>drivers\framework\include\wifi\wifi_module.h</p>
</td>
<td class="cellrowborder" valign="top" width="43.23432343234324%" headers="mcps1.1.4.1.3 "><p id="p26814555217"><a name="p26814555217"></a><a name="p26814555217"></a>Manages a specific WLAN interface.</p>
</td>
</tr>
<tr id="row13686559215"><td class="cellrowborder" valign="top" width="17.28172817281728%" headers="mcps1.1.4.1.1 "><p id="p76810555214"><a name="p76810555214"></a><a name="p76810555214"></a>NetDeviceInterFace</p>
</td>
<td class="cellrowborder" valign="top" width="39.48394839483948%" headers="mcps1.1.4.1.2 "><p id="p166818551825"><a name="p166818551825"></a><a name="p166818551825"></a>drivers\framework\include\wifi\net_device.h</p>
</td>
<td class="cellrowborder" valign="top" width="43.23432343234324%" headers="mcps1.1.4.1.3 "><p id="p368195513213"><a name="p368195513213"></a><a name="p368195513213"></a>Communicates with the protocol stack, such as sending data and setting the status of network interfaces.</p>
</td>
</tr>
</tbody>
</table>
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>For details about the API development, see [WLAN Development Guidelines](../driver/driver-peripherals-external-des.md).
The porting procedure is as follows: The porting procedure is as follows:
1. Create a WLAN chip driver. 1. Create a WLAN chip driver.
Create the **hdf\_wlan\_chip\_name.c** file in **/device/vendor\_name/peripheral/wifi/chip\_name/**. The sample code is as follows: Create the **hdf_wlan_chip_name.c** file in **/device/vendor_name/peripheral/wifi/chip_name/**. The sample code is as follows:
``` ```
static int32_t HdfWlanHisiChipDriverInit(struct HdfDeviceObject *device) { static int32_t HdfWlanXXXChipDriverInit(struct HdfDeviceObject *device) {
static struct HdfChipDriverFactory factory = CreateChipDriverFactory(); // Implement the method. static struct HdfChipDriverFactory factory = CreateChipDriverFactory(); // Implement the method.
struct HdfChipDriverManager *driverMgr = HdfWlanGetChipDriverMgr(); struct HdfChipDriverManager *driverMgr = HdfWlanGetChipDriverMgr();
if (driverMgr->RegChipDriver(&factory) != HDF_SUCCESS) {// Register the driver factory. if (driverMgr->RegChipDriver(&factory) != HDF_SUCCESS) { // Register the driver factory.
HDF_LOGE("%s fail: driverMgr is NULL!", __func__); HDF_LOGE("%s fail: driverMgr is NULL!", __func__);
return HDF_FAILURE; return HDF_FAILURE;
} }
return HDF_SUCCESS; return HDF_SUCCESS;
} }
struct HdfDriverEntry g_hdfXXXChipEntry = { struct HdfDriverEntry g_hdfXXXChipEntry = {
.moduleVersion = 1, .moduleVersion = 1,
.Init = HdfWlanXXXChipDriverInit, .Init = HdfWlanXXXChipDriverInit,
.Release = HdfWlanXXXChipRelease, .Release = HdfWlanXXXChipRelease,
.moduleName = "HDF_WIFI_CHIP_XXX" // Make sure the name is the same as the configured one. .moduleName = "HDF_WIFI_CHIP_XXX" // Make sure the name is the same as the configured one.
}; };
HDF_INIT(g_hdfXXXChipEntry);
```
In the **CreateChipDriverFactory** method, create an object of the **HdfChipDriverFactory** type. This object provides the following methods:
HDF_INIT(g_hdfXXXChipEntry); | Method | Description |
``` | -------- | -------- |
| const&nbsp;char&nbsp;\*driverName | Indicates the driver name. |
In the **CreateChipDriverFactory** method, create an object of the **HdfChipDriverFactory** type. This object provides the following methods: | int32_t&nbsp;(\*InitChip)(struct&nbsp;HdfWlanDevice&nbsp;\*device) | Initializes the chip. |
| int32_t&nbsp;(\*DeinitChip)(struct&nbsp;HdfWlanDevice&nbsp;\*device) | Deinitializes the chip. |
<a name="table8351533595"></a> | void&nbsp;(\*ReleaseFactory)(struct&nbsp;HdfChipDriverFactory&nbsp;\*factory) | Releases the **HdfChipDriverFactory** object. |
<table><thead align="left"><tr id="row25693318916"><th class="cellrowborder" valign="top" width="50%" id="mcps1.1.3.1.1"><p id="p125683311913"><a name="p125683311913"></a><a name="p125683311913"></a>Method</p> | struct&nbsp;HdfChipDriver&nbsp;\*(\*Build)(struct&nbsp;HdfWlanDevice&nbsp;\*device,&nbsp;uint8_t&nbsp;ifIndex) | Creates an **HdfChipDriver**. In the input parameters, **device** indicates the device information, and **ifIndex** indicates the sequence number of this interface in the chip. |
</th> | void&nbsp;(\*Release)(struct&nbsp;HdfChipDriver&nbsp;\*chipDriver) | Releases the chip driver. |
<th class="cellrowborder" valign="top" width="50%" id="mcps1.1.3.1.2"><p id="p1656103318919"><a name="p1656103318919"></a><a name="p1656103318919"></a>Description</p> | uint8_t&nbsp;(\*GetMaxIFCount)(struct&nbsp;HdfChipDriverFactory&nbsp;\*factory) | Obtains the maximum number of interfaces supported by the current chip. |
</th>
</tr> The **Build** method creates an **HdfChipDriver** object that manages the specified network interface. This object needs to provide the following methods:
</thead>
<tbody><tr id="row15612331994"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p185663314920"><a name="p185663314920"></a><a name="p185663314920"></a>const char *driverName</p> | Method | Description |
</td> | -------- | -------- |
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p7563330917"><a name="p7563330917"></a><a name="p7563330917"></a>Indicates the driver name.</p> | int32_t&nbsp;(\*init)(struct&nbsp;HdfChipDriver&nbsp;\*chipDriver,&nbsp;NetDevice&nbsp;\*netDev) | Initializes the current network interface. The **NetDeviceInterFace** needs to be provided for the **netDev**. |
</td> | int32_t&nbsp;(\*deinit)(struct&nbsp;HdfChipDriver&nbsp;\*chipDriver,&nbsp;NetDevice&nbsp;\*netDev) | Deinitializes the current network interface. |
</tr> | struct&nbsp;HdfMac80211BaseOps&nbsp;\*ops | Provides the WLAN basic capability interface set. |
<tr id="row20561733993"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p13561331297"><a name="p13561331297"></a><a name="p13561331297"></a>int32_t (*InitChip)(struct HdfWlanDevice *device)</p> | struct&nbsp;HdfMac80211STAOps&nbsp;\*staOps | Provides the interface set required for supporting the STA mode. |
</td> | struct&nbsp;HdfMac80211APOps&nbsp;\*apOps | Provides the interface set required for supporting the AP mode. |
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p756163312914"><a name="p756163312914"></a><a name="p756163312914"></a>Initializes the chip.</p>
</td>
</tr>
<tr id="row155612337919"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p135633315917"><a name="p135633315917"></a><a name="p135633315917"></a>int32_t (*DeinitChip)(struct HdfWlanDevice *device)</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p3566331094"><a name="p3566331094"></a><a name="p3566331094"></a>Deinitializes the chip.</p>
</td>
</tr>
<tr id="row18567337916"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p157203315917"><a name="p157203315917"></a><a name="p157203315917"></a>void (*ReleaseFactory)(struct HdfChipDriverFactory *factory)</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p165716331596"><a name="p165716331596"></a><a name="p165716331596"></a>Releases the <strong id="b17274134462416"><a name="b17274134462416"></a><a name="b17274134462416"></a>HdfChipDriverFactory</strong> object.</p>
</td>
</tr>
<tr id="row1757143314912"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p105710331694"><a name="p105710331694"></a><a name="p105710331694"></a>struct HdfChipDriver *(*Build)(struct HdfWlanDevice *device, uint8_t ifIndex)</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p457143320911"><a name="p457143320911"></a><a name="p457143320911"></a>Creates an <strong id="b118260459243"><a name="b118260459243"></a><a name="b118260459243"></a>HdfChipDriver</strong>. In the input parameters, <strong id="b28271845162411"><a name="b28271845162411"></a><a name="b28271845162411"></a>device</strong> indicates the device information, and <strong id="b16827144519241"><a name="b16827144519241"></a><a name="b16827144519241"></a>ifIndex</strong> indicates the sequence number of this interface in the chip.</p>
</td>
</tr>
<tr id="row1157153310912"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p155714334917"><a name="p155714334917"></a><a name="p155714334917"></a>void (*Release)(struct HdfChipDriver *chipDriver)</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p95717338919"><a name="p95717338919"></a><a name="p95717338919"></a>Releases the chip driver.</p>
</td>
</tr>
<tr id="row1157143313914"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p19571433993"><a name="p19571433993"></a><a name="p19571433993"></a>uint8_t (*GetMaxIFCount)(struct HdfChipDriverFactory *factory)</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p14571334915"><a name="p14571334915"></a><a name="p14571334915"></a>Obtains the maximum number of interfaces supported by the current chip.</p>
</td>
</tr>
</tbody>
</table>
The **Build** method creates an **HdfChipDriver** object that manages the specified network interface. This object needs to provide the following methods:
<a name="table16989183941017"></a>
<table><thead align="left"><tr id="row61014406100"><th class="cellrowborder" valign="top" width="50%" id="mcps1.1.3.1.1"><p id="p111094011015"><a name="p111094011015"></a><a name="p111094011015"></a>Method</p>
</th>
<th class="cellrowborder" valign="top" width="50%" id="mcps1.1.3.1.2"><p id="p11102040201014"><a name="p11102040201014"></a><a name="p11102040201014"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row111014409104"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p21084017106"><a name="p21084017106"></a><a name="p21084017106"></a>int32_t (*init)(struct HdfChipDriver *chipDriver, NetDevice *netDev)</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p1310184012103"><a name="p1310184012103"></a><a name="p1310184012103"></a>Initializes the current network interface. The <strong id="b18435181416253"><a name="b18435181416253"></a><a name="b18435181416253"></a>NetDeviceInterFace</strong> needs to be provided for the <strong id="b1543511144251"><a name="b1543511144251"></a><a name="b1543511144251"></a>netDev</strong>.</p>
</td>
</tr>
<tr id="row210840101012"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p71064031013"><a name="p71064031013"></a><a name="p71064031013"></a>int32_t (*deinit)(struct HdfChipDriver *chipDriver, NetDevice *netDev)</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p710144015101"><a name="p710144015101"></a><a name="p710144015101"></a>Deinitializes the current network interface.</p>
</td>
</tr>
<tr id="row151094011100"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p1910340171018"><a name="p1910340171018"></a><a name="p1910340171018"></a>struct HdfMac80211BaseOps *ops</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p31034071020"><a name="p31034071020"></a><a name="p31034071020"></a>Provides the WLAN basic capability interface set.</p>
</td>
</tr>
<tr id="row91012407102"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p191014051019"><a name="p191014051019"></a><a name="p191014051019"></a>struct HdfMac80211STAOps *staOps</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p810104013106"><a name="p810104013106"></a><a name="p810104013106"></a>Provides the interface set required for supporting the STA mode.</p>
</td>
</tr>
<tr id="row17101840111020"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p1010204081015"><a name="p1010204081015"></a><a name="p1010204081015"></a>struct HdfMac80211APOps *apOps</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p710184013105"><a name="p710184013105"></a><a name="p710184013105"></a>Provides the interface set required for supporting the AP mode.</p>
</td>
</tr>
</tbody>
</table>
2. Create a configuration file to describe the chips supported by the driver. 2. Create a configuration file to describe the chips supported by the driver.
Create a chip configuration file in the product configuration directory and save it to the source code path **//vendor/vendor\_name/product\_name/config/wifi/wlan\_chip\_chip\_name.hcs**. Create a chip configuration file in the product configuration directory and save it to the source code path **//vendor/vendor\_name/product\_name/config/wifi/wlan\_chip\_chip\_name.hcs**.
The sample code is as follows:
```
root { ```
wlan_config { root {
chip_name :& chipList { wlan_config {
chip_name :: chipInst { chip_name :& chipList {
match_attr = "hdf_wlan_chips_chip_name"; /* Indicates the configuration matching attribute, which is used to provide the configuration root of the driver.*/ chip_name :: chipInst {
driverName = "driverName"; /* Indicates the driver name, which must be the same as that of driverName in HdfChipDriverFactory.*/ match_attr = "hdf_wlan_chips_chip_name"; /* Indicates the configuration matching attribute, which is used to provide the configuration root of the driver. */
sdio { driverName = "driverName"; /* Indicates the driver name, which must be the same as that of driverName in HdfChipDriverFactory.*/
vendorId = 0xXXXX; /* your vendor id */ sdio {
deviceId = [0xXXXX]; /*your supported devices */ vendorId = 0xXXXX; /* your vendor id */
} deviceId = [0xXXXX]; /*your supported devices */
} }
} }
} }
} }
``` }
```
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>Replace the values of **vendor\_name**, **product\_name**, and **chip\_name** in the path and file with the actual names. > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
>Set **vendorId** and **deviceId** to the actual vendor ID and chip ID, respectively. >
> Replace the values of **vendor\_name**, **product\_name**, and **chip\_name** in the path and file with the actual names.
>
> Set **vendorId** and **deviceId** to the actual vendor ID and chip ID, respectively.
3. Edit the configuration file and load the driver. 3. Edit the configuration file and load the driver.
All device information of the product is defined in the source code file **//vendor/vendor\_name/product\_name/config/device\_info/device\_info.hcs**. Modify the file and add configurations to the **device** named **device\_wlan\_chips** in the **host** of the **network** command. The sample code is as follows: All device information of the product is defined in the source code file **//vendor/vendor\_name/product\_name/config/device\_info/device\_info.hcs**. Modify the file and add configurations to the **device** named **device\_wlan\_chips** in the **host** of the **network** command. The sample code is as follows:
``` ```
deviceN :: deviceNode { deviceN :: deviceNode {
policy = 0; policy = 0;
preload = 2; preload = 2;
moduleName = "HDF_WLAN_CHIPS"; moduleName = "HDF_WLAN_CHIPS";
deviceMatchAttr = "hdf_wlan_chips_chip_name"; deviceMatchAttr = "hdf_wlan_chips_chip_name";
serviceName = "driverName"; serviceName = "driverName";
} }
``` ```
>![](../public_sys-resources/icon-note.gif) **NOTE:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
>Make sure the value of **moduleName** is the same as that of **moduleName** in the WLAN driver. >
> Make sure the value of **moduleName** is the same as that of **moduleName** in the WLAN driver.
4. Modify the **Kconfig** file to make the ported WLAN driver appear in the kernel configuration. 4. Modify the **Kconfig** file to make the ported WLAN driver appear in the kernel configuration.
Add configurations to **device/vendor\_name/drivers/Kconfig**. The sample code is as follows: Add configurations to **device/vendor\_name/drivers/Kconfig**. The sample code is as follows:
```
config DRIVERS_HDF_WIFI_chip_name
bool "Enable chip_name Host driver"
default n
depends on DRIVERS_HDF_WLAN help
Answer Y to enable chip_name Host driver.
```
>![](../public_sys-resources/icon-note.gif) **NOTE:** ```
>Replace **chip\_name** with the actual chip name. config DRIVERS_HDF_WIFI_chip_name
bool "Enable chip_name Host driver"
default n
depends on DRIVERS_HDF_WLAN help
Answer Y to enable chip_name Host driver.
```
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
>
> Replace **chip\_name** with the actual chip name.
5. Modify the build script to enable the driver to participate in the kernel build. 5. Modify the build script to enable the driver to participate in the kernel build.
Add the following content to the end of the source code file **//device/vendor\_name/drivers/lite.mk**: Add the following content to the end of the source code file **//device/vendor\_name/drivers/lite.mk**:
``` ```
ifeq ($(LOSCFG_DRIVERS_HDF_WIFI_chip_name), y) ifeq ($(LOSCFG_DRIVERS_HDF_WIFI_chip_name), y)
# After the build is complete, an object named hdf_wlan_chipdriver_chip_name needs to be linked. You are advised to use this name to prevent conflicts. # After the build is complete, an object named hdf_wlan_chipdriver_chip_name needs to be linked. You are advised to use this name to prevent conflicts.
LITEOS_BASELIB += -lhdf_wlan_chipdriver_chip_name LITEOS_BASELIB += -lhdf_wlan_chipdriver_chip_name
# Add the build directory gpio. # Add the build directory gpio.
LIB_SUBDIRS += ../peripheral/wifi/chip_name LIB_SUBDIRS += ../peripheral/wifi/chip_name
endif endif
``` ```
>![](../public_sys-resources/icon-note.gif) **NOTE:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
>Replace **chip\_name** with the actual chip name. >
> Replace **chip_name** with the actual chip name.
...@@ -30,10 +30,10 @@ Create a file named **config.json** in the **//vendor/MyProductVendor/*{product_ ...@@ -30,10 +30,10 @@ Create a file named **config.json** in the **//vendor/MyProductVendor/*{product_
{ {
"subsystem": "ace", "subsystem": "ace",
"components": [ "components": [
{ "component": "ace_engine_lite", "features":[""] } { "component": "ace_engine_lite", "features":[] }
] ]
} },
...
] ]
} }
...@@ -41,29 +41,20 @@ Create a file named **config.json** in the **//vendor/MyProductVendor/*{product_ ...@@ -41,29 +41,20 @@ Create a file named **config.json** in the **//vendor/MyProductVendor/*{product_
``` ```
The main configurations are as follows: The main configurations are as follows:
**product_name**: product name. This parameter is required. | Item| Description|
|-------|----------|
**version**: version. This parameter is required. |product_name |(Mandatory) Product name.|
|version|(Mandatory) Version.|
**type**: system level, such as **small** or **standard**. This parameter is required. |type|(Mandatory) System level, such as **small** and **standard**.|
|target_cpu |(Mandatory) CPU type of the device, such as **arm64**, **riscv**, or **x86**.|
**target_cpu**: CPU type of the device, such as **arm64**, **riscv**, or **x86**. This parameter is required. |ohos_version|(Optional) Operating system version.|
|device_company|(Mandatory) Device manufacturer name.|
**ohos_version**: operating system version. This parameter is optional. |board|(Mandatory) Development board name.|
|enable_ramdisk|(Mandatory) Whether to start the RAM disk.|
**device_company**: device manufacturer name. This parameter is required. |kernel_type|(Optional) Kernel type.|
|kernel_version|(Optional) Kernel version. The values of both **kernel_type** and **kernel_version** are fixed in the standard system.|
**board**: board name. This parameter is required. |subsystems|(Mandatory) Subsystem to enable. A subsystem can be treated as an independently built functional block.|
|product_company|Device manufacturer name. It is not set in the configuration, but in the directory name, next to the vendor name. It can be accessed from **build.gn script**.|
**enable_ramdisk**: whether to enable the RAM disk. This parameter is required.
**kernel_type**: kernel type. This parameter is optional.
**kernel_version**: kernel version. This parameter is optional. Both **kernel_type** and **kernel_version** are fixed.
**subsystems**: subsystem to enable. A subsystem can be treated as an independently built functional block. This parameter is required.
**product_company**: device manufacturer name. It is not set in the configuration, but in the directory name, next to the vendor name. It can be accessed from **build.gn script**.
You can find predefined subsystems in **//build/subsystem_config.json**. You can also customize subsystems. You can find predefined subsystems in **//build/subsystem_config.json**. You can also customize subsystems.
...@@ -89,7 +80,7 @@ Now, you need to port the Linux kernel to enable it to run successfully. ...@@ -89,7 +80,7 @@ Now, you need to port the Linux kernel to enable it to run successfully.
### Adding a Kernel-built Subsystem to the SoC ### Adding a Kernel-built Subsystem to the SoC
Add the following subsystem configuration to the **//build/subsystem_config.json** file: Modify the **//build/subsystem_config.json** file to add a subsystem. For example, if **product_name** is **MyProduct**, configure the **//vendor/MyProductVendor/MyProduct/config.json** file as follows:
``` ```
...@@ -126,10 +117,10 @@ The **BUILD.gn** file is the only entry for building the subsystem. ...@@ -126,10 +117,10 @@ The **BUILD.gn** file is the only entry for building the subsystem.
The expected build result described in the table below. The expected build result described in the table below.
| File| Description| | File| Description|
| -------- | -------- | | -------- | -------- |
| $root_build_dir/packages/phone/images/uImage | Kernel image.| | $root_build_dir/packages/phone/images/uImage | Kernel image.|
| $root_build_dir/packages/phone/images/uboot | Bootloader image.| | $root_build_dir/packages/phone/images/uboot | Bootloader image.|
### Verifying the Porting ### Verifying the Porting
...@@ -140,17 +131,18 @@ Now start build, and check whether the kernel image is generated as expected. ...@@ -140,17 +131,18 @@ Now start build, and check whether the kernel image is generated as expected.
1. Overview of user-mode boot process 1. Overview of user-mode boot process
![user-mode boot](figures/user-mode boot.png) ![user-mode boot](figures/user-mode boot.png)
When the system is powered on, the kernel loads and starts services and applications as follows: When the system is powered on, the kernel loads and starts services and applications as follows:
1. The kernel loads the init process, which is specified by **cmdline** of the kernel when the bootloader starts the kernel, for example, **init=/init root/dev/xxx**. 1. The kernel loads the init process, which is specified by **cmdline** of the kernel when the bootloader starts the kernel, for example, **init=/init root/dev/xxx**.
2. After the init process is started, **tmpfs** and **procfs** are mounted and basic **dev** nodes are created to establish a basic root file system. 2. After the init process is started, **tmpfs** and **procfs** are mounted and basic **dev** nodes are created to establish a basic root file system.
3. The init process starts the ueventd process to listen for device hot-swap events in the kernel and creates **dev** nodes for related devices as well as partitions for the block device. 3. The init process starts the ueventd process to listen for device hot-swap events in the kernel and creates **dev** nodes for related devices as well as partitions for the block device.
4. After mounting partitions (**system** and **vendor**) of the block device, the init process scans for the init startup script of each system service and launches the respective service ability (SA). 4. After mounting partitions (**system** and **vendor**) of the block device, the init process scans for the init startup script of each system service and launches the respective service ability (SA).
5. Each SA registers with the samgr process, which serves as the service registration center. The samgr process assigns each SA with an ID, which will be used by an application to access the desired SA. 5. Each SA registers with the samgr process, which serves as the service registration center. The samgr process assigns each SA with an ID, which will be used by an application to access the desired SA.
6. The foundation process implements application lifecycle management. It is a special SA service process that provides the user program management framework and basic services. 6. The foundation process implements application lifecycle management. It is a special SA service process that provides the user program management framework and basic services.
7. The appspawn process directly spawns the application process, eliminating the need for the application to load the JS runtime environment. This reduces the application startup time. 7. The appspawn process directly spawns the application process, eliminating the need for the application to load the JS runtime environment. This reduces the application startup time.
2. init module 2. init module
...@@ -158,7 +150,7 @@ Now start build, and check whether the kernel image is generated as expected. ...@@ -158,7 +150,7 @@ Now start build, and check whether the kernel image is generated as expected.
When porting a new chip platform, you need to add the **/vendor/etc/init/init.{hardware}.cfg** file that contains the platform-level initialization configuration. This file is used to implement platform-level initialization, for example, installing the ko driver and configuring information on the related **/proc** nodes. When porting a new chip platform, you need to add the **/vendor/etc/init/init.{hardware}.cfg** file that contains the platform-level initialization configuration. This file is used to implement platform-level initialization, for example, installing the ko driver and configuring information on the related **/proc** nodes.
The code of the init process is stored in the **//base/startup/init** directory. This process is the first process in the system and does not depend on other processes. The code of the init process is stored in the **//base/startup/init_lite** directory. This process is the first process in the system and does not depend on other processes.
For details about how to develop the initialization configuration file, see [Startup](../subsystems/subsys-boot-overview.md). For details about how to develop the initialization configuration file, see [Startup](../subsystems/subsys-boot-overview.md).
...@@ -170,180 +162,184 @@ Now start build, and check whether the kernel image is generated as expected. ...@@ -170,180 +162,184 @@ Now start build, and check whether the kernel image is generated as expected.
This section describes how to port a Liquid Crystal Display (LCD) driver. The hardware driver framework (HDF) designs a driver model for the LCD. To support an LCD, you must compile a driver, generate a model instance in the driver, and register the instance. This section describes how to port a Liquid Crystal Display (LCD) driver. The hardware driver framework (HDF) designs a driver model for the LCD. To support an LCD, you must compile a driver, generate a model instance in the driver, and register the instance.
The LCD drivers are stored in the **//drivers/framework/model/display/driver/panel** directory. The LCD drivers are stored in the **//drivers/hdf_core/framework/model/display/driver/panel** directory.
- Create a panel driver. 1. Create a panel driver.
In the **Init** method of the driver, call **RegisterPanel** to register the model instance. In the **Init** method of the driver, call **RegisterPanel** to register the model instance. For example:
``` ```
int32_t XXXInit(struct HdfDeviceObject *object) int32_t XXXInit(struct HdfDeviceObject *object)
{ {
struct PanelData *panel = CreateYourPanel(); struct PanelData *panel = CreateYourPanel();
// Registration
if (RegisterPanel(panel) != HDF_SUCCESS) {
HDF_LOGE("%s: RegisterPanel failed", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
struct HdfDriverEntry g_xxxxDevEntry = { // Registration
.moduleVersion = 1, if (RegisterPanel(panel) != HDF_SUCCESS) {
.moduleName = "LCD_XXXX", HDF_LOGE("%s: RegisterPanel failed", __func__);
.Init = XXXInit, return HDF_FAILURE;
}; }
return HDF_SUCCESS;
}
HDF_INIT(g_xxxxDevEntry); struct HdfDriverEntry g_xxxxDevEntry = {
``` .moduleVersion = 1,
.moduleName = "LCD_XXXX",
.Init = XXXInit,
};
- Configure and load the panel driver. All device information about the product is defined in the **//vendor/MyProductVendor/MyProduct/config/device_info/device_info.hcs** file. Modify the file by adding configurations for the device named **device_lcd** to the host named **display**. Note: The value of **moduleName** must be the same as that in the panel driver. HDF_INIT(g_xxxxDevEntry);
```
2. Configure and load the panel driver. All device information about the product is defined in the **//vendor/MyProductVendor/MyProduct/config/device_info/device_info.hcs** file. Modify the file by adding configurations for the device named **device_lcd** to the host named **display**.
```
root { Note: The value of **moduleName** must be the same as that in the panel driver.
...
display :: host {
device_lcd :: device {
deviceN :: deviceNode {
policy = 0;
priority = 100;
preload = 2;
moduleName = "LCD_XXXX";
}
}
}
}
```
For details about driver development, see [LCD](../driver/driver-peripherals-lcd-des.md). ```
root {
...
display :: host {
device_lcd :: device {
deviceN :: deviceNode {
policy = 0;
priority = 100;
preload = 2;
moduleName = "LCD_XXXX";
}
}
}
}
```
For details about driver development, see [LCD](../driver/driver-peripherals-lcd-des.md).
### Touchscreen ### Touchscreen
This section describes how to port a touchscreen driver. The touchscreen driver is stored in the **//drivers/framework/model/input/driver/touchscreen** directory. To port a touchscreen driver, register a **ChipDevice** model instance. This section describes how to port a touchscreen driver. The touchscreen driver is stored in the **//drivers/hdf_core/framework/model/input/driver/touchscreen** directory. To port a touchscreen driver, register a **ChipDevice** model instance.
- Create a touchscreen driver. 1. Create a touchscreen driver.
Create the **touch_ic_name.c** file in the directory. Replace **ic_name** with the name of your chip. The file template is as follows: Create the **touch_ic_name.c** file in the directory. Replace **ic_name** with the name of your chip. The file template is as follows:
``` ```
#include "hdf_touch.h" #include "hdf_touch.h"
static int32_t HdfXXXXChipInit(struct HdfDeviceObject *device) static int32_t HdfXXXXChipInit(struct HdfDeviceObject *device)
{ {
ChipDevice *tpImpl = CreateXXXXTpImpl(); ChipDevice *tpImpl = CreateXXXXTpImpl();
if(RegisterChipDevice(tpImpl) != HDF_SUCCESS) { if(RegisterChipDevice(tpImpl) != HDF_SUCCESS) {
ReleaseXXXXTpImpl(tpImpl); ReleaseXXXXTpImpl(tpImpl);
return HDF_FAILURE; return HDF_FAILURE;
} }
return HDF_SUCCESS; return HDF_SUCCESS;
} }
struct HdfDriverEntry g_touchXXXXChipEntry = { struct HdfDriverEntry g_touchXXXXChipEntry = {
.moduleVersion = 1, .moduleVersion = 1,
.moduleName = "HDF_TOUCH_XXXX", .moduleName = "HDF_TOUCH_XXXX",
.Init = HdfXXXXChipInit, .Init = HdfXXXXChipInit,
}; };
HDF_INIT(g_touchXXXXChipEntry); HDF_INIT(g_touchXXXXChipEntry);
``` ```
Implement the following APIs in **ChipDevice**: Implement the following interfaces in **ChipDevice**:
| API| Description| | API| Description|
| -------- | -------- | | -------- | -------- |
| int32_t&nbsp;(\*Init)(ChipDevice&nbsp;\*device) | Initializes a touchscreen.| | int32_t (\*Init)(ChipDevice \*device) | Initializes a touchscreen.|
| int32_t&nbsp;(\*Detect)(ChipDevice&nbsp;\*device) | Detects a touchscreen.| | int32_t (\*Detect)(ChipDevice \*device) | Detects a touchscreen.|
| int32_t&nbsp;(\*Suspend)(ChipDevice&nbsp;\*device) | Suspends a touchscreen.| | int32_t (\*Suspend)(ChipDevice \*device) | Suspends a touchscreen.|
| int32_t&nbsp;(\*Resume)(ChipDevice&nbsp;\*device) | Resumes a touchscreen.| | int32_t (\*Resume)(ChipDevice \*device) | Resumes a touchscreen.|
| int32_t&nbsp;(\*DataHandle)(ChipDevice&nbsp;\*device) | Reads data from a touchscreen and writes the touch point data to **device** > **driver** > **frameData**.| | int32_t (\*DataHandle)(ChipDevice \*device) | Reads data from a touchscreen and writes the touch point data to **device** > **driver** > **frameData**.|
| int32_t&nbsp;(\*UpdateFirmware)(ChipDevice&nbsp;\*device) | Upgrades the firmware.| | int32_t (\*UpdateFirmware)(ChipDevice \*device) | Upgrades the firmware.|
- Configure the product and load the driver. 2. Configure the product and load the driver.
All device information about the product is defined in the **//vendor/MyProductVendor/MyProduct/config/device_info/device_info.hcs** file. Modify the file by adding configurations for the device named **device_touch_chip** to the host named **input**. Note: The value of **moduleName** must be the same as that in the touchscreen driver. All device information about the product is defined in the **//vendor/MyProductVendor/MyProduct/config/device_info/device_info.hcs** file. Modify the file by adding configurations for the device named **device_touch_chip** to the host named **input**. Note: The value of **moduleName** must be the same as that in the touchscreen driver.
```
deviceN :: deviceNode { ```
policy = 0; deviceN :: deviceNode {
priority = 130; policy = 0;
preload = 0; priority = 130;
permission = 0660; preload = 0;
moduleName = "HDF_TOUCH_XXXX"; permission = 0660;
deviceMatchAttr = "touch_XXXX_configs"; moduleName = "HDF_TOUCH_XXXX";
} deviceMatchAttr = "touch_XXXX_configs";
``` }
```
For details about driver development, see [Touchscreen](../driver/driver-peripherals-touch-des.md). For details about driver development, see [Touchscreen](../driver/driver-peripherals-touch-des.md).
### WLAN ### WLAN
The WLAN driver is divided into two parts. One of the parts manages WLAN devices, and the other part manages WLAN traffic. HDF WLAN provides abstraction for the two parts. Currently, only the WLAN with the SDIO interface is supported. The WLAN driver is divided into two parts. One of the parts manages WLAN devices, and the other part manages WLAN traffic. HDF WLAN provides abstraction for the two parts. Currently, only the WLAN with the SDIO interface is supported.
**Figure 1** WLAN chip **Figure 1** WLAN chip
![hdf_wifi](figures/hdf_wifi.png) ![hdf_wifi](figures/hdf_wifi.png)
To support a chip, implement a **ChipDriver** for it. The major task is to implement the following interfaces provided by **HDF_WLAN_CORE** and **NetDevice**. To support a chip, implement a **ChipDriver** for it. The major task is to implement the following interfaces provided by **HDF_WLAN_CORE** and **NetDevice**.
| API| Header File| Description| | API| Header File| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| HdfChipDriverFactory | //drivers/framework/include/wifi/hdf_wlan_chipdriver_manager.h | Supports multiple WLAN interfaces of a chip.| | HdfChipDriverFactory | //drivers/hdf_core/framework/include/wifi/hdf_wlan_chipdriver_manager.h | Supports multiple WLAN interfaces of a chip.|
| HdfChipDriver | //drivers/framework/include/wifi/wifi_module.h | Manages a specific WLAN interface. Each WLAN interface corresponds to an **HdfChipDriver**.| | HdfChipDriver | //drivers/hdf_core/framework/include/wifi/wifi_module.h | Manages a specific WLAN interface. Each WLAN interface corresponds to an **HdfChipDriver**.|
| NetDeviceInterFace | //drivers/framework/include/net/net_device.h | Communicates with the protocol stack, such as sending data and setting the status of network interfaces.| | NetDeviceInterFace | //drivers/hdf_core/framework/include/net/net_device.h | Communicates with the protocol stack, such as sending data and setting the status of network interfaces.|
To port a WLAN driver, perform the following steps: To port a WLAN driver, perform the following steps:
1. Create an HDF driver. You are advised to place the code file in the **//device/MySoCVendor/peripheral/wifi/chip_name/** directory. The file template is as follows: 1. Create an HDF driver. You are advised to place the code file in the **//device/MySoCVendor/peripheral/wifi/chip_name/** directory. The file template is as follows:
``` ```
static int32_t HdfWlanHisiChipDriverInit(struct HdfDeviceObject *device) { static int32_t HdfWlanXXXChipDriverInit(struct HdfDeviceObject *device) {
static struct HdfChipDriverFactory factory = CreateChipDriverFactory(); static struct HdfChipDriverFactory factory = CreateChipDriverFactory();
struct HdfChipDriverManager *driverMgr = HdfWlanGetChipDriverMgr(); struct HdfChipDriverManager *driverMgr = HdfWlanGetChipDriverMgr();
if (driverMgr->RegChipDriver(&factory) != HDF_SUCCESS) { if (driverMgr->RegChipDriver(&factory) != HDF_SUCCESS) {
HDF_LOGE("%s fail: driverMgr is NULL!", __func__); HDF_LOGE("%s fail: driverMgr is NULL!", __func__);
return HDF_FAILURE; return HDF_FAILURE;
} }
return HDF_SUCCESS; return HDF_SUCCESS;
} }
struct HdfDriverEntry g_hdfXXXChipEntry = { struct HdfDriverEntry g_hdfXXXChipEntry = {
.moduleVersion = 1, .moduleVersion = 1,
.Init = HdfWlanXXXChipDriverInit, .Init = HdfWlanXXXChipDriverInit,
.Release = HdfWlanXXXChipRelease, .Release = HdfWlanXXXChipRelease,
.moduleName = "HDF_WIFI_CHIP_XXX" .moduleName = "HDF_WIFI_CHIP_XXX"
}; };
HDF_INIT(g_hdfXXXChipEntry); HDF_INIT(g_hdfXXXChipEntry);
``` ```
Create an **HdfChipDriverFactory** in the **CreateChipDriverFactory**. The APIs are as follows: Create an **HdfChipDriverFactory** in the **CreateChipDriverFactory**. The APIs are as follows:
| API| Description|
| -------- | -------- |
| const&nbsp;char&nbsp;\*driverName | Indicates the driver name.|
| int32_t&nbsp;(\*InitChip)(struct&nbsp;HdfWlanDevice&nbsp;\*device) | Initializes a chip.|
| int32_t&nbsp;(\*DeinitChip)(struct&nbsp;HdfWlanDevice&nbsp;\*device) | Deinitializes a chip.|
| void&nbsp;(*ReleaseFactory)(struct&nbsp;HdfChipDriverFactory&nbsp;*factory) | Releases the **HdfChipDriverFactory** object.|
| struct&nbsp;HdfChipDriver&nbsp;*(_Build)(struct&nbsp;HdfWlanDevice&nbsp;\*device,&nbsp;uint8*t&nbsp;ifIndex) | Creates an **HdfChipDriver**. In the input parameters, **device** indicates the device information, and **ifIndex** indicates the sequence number of this interface in the chip.|
| void&nbsp;(*Release)(struct&nbsp;HdfChipDriver&nbsp;*chipDriver) | Releases the **HdfChipDriver**.|
| uint8_t&nbsp;(\*GetMaxIFCount)(struct&nbsp;HdfChipDriverFactory&nbsp;\*factory) | Obtains the maximum number of APIs supported by the current chip.|
Implement the following APIs in the **HdfChipDriver**.
| API| Description| | API| Description|
| -------- | -------- | | -------- | -------- |
| int32_t&nbsp;(\*init)(struct&nbsp;HdfChipDriver&nbsp;\*chipDriver,&nbsp;NetDevice&nbsp;\*netDev) | Initializes the current network interface. The **NetDeviceInterFace** needs to be provided for the **netDev**.| | const char \*driverName | Indicates the driver name.|
| int32_t&nbsp;(\*deinit)(struct&nbsp;HdfChipDriver&nbsp;\*chipDriver,&nbsp;NetDevice&nbsp;\*netDev) | Deinitializes the current network interface.| | int32_t (\*InitChip)(struct HdfWlanDevice \*device) | Initializes a chip.|
| struct&nbsp;HdfMac80211BaseOps&nbsp;\*ops | Provides the WLAN basic capability interface set.| | int32_t (\*DeinitChip)(struct HdfWlanDevice \*device) | Deinitializes a chip.|
| struct&nbsp;HdfMac80211STAOps&nbsp;\*staOps | Provides the interface set required for supporting the standalone (STA) mode.| | void (_ReleaseFactory)(struct HdfChipDriverFactory _factory) | Releases the **HdfChipDriverFactory** object.|
| struct&nbsp;HdfMac80211APOps&nbsp;\*apOps | Provides the interface set required for supporting the access point (AP) mode.| | struct HdfChipDriver _(_Build)(struct HdfWlanDevice \*device, uint8_t ifIndex) | Creates an **HdfChipDriver**. In the input parameters, **device** indicates the device information, and **ifIndex** indicates the sequence number of this interface in the chip.|
| void (_Release)(struct HdfChipDriver _chipDriver) | Releases the **HdfChipDriver**.|
| uint8_t (\*GetMaxIFCount)(struct HdfChipDriverFactory \*factory) | Obtains the maximum number of APIs supported by the current chip.|
Implement the following APIs in the **HdfChipDriver**.
| API| Description|
| -------- | -------- |
| int32_t (\*init)(struct HdfChipDriver \*chipDriver, NetDevice \*netDev) | Initializes the current network interface. The **NetDeviceInterFace** needs to be provided for the **netDev**.|
| int32_t (\*deinit)(struct HdfChipDriver \*chipDriver, NetDevice \*netDev) | Deinitializes the current network interface.|
| struct HdfMac80211BaseOps \*ops | Provides the WLAN basic capability interface set.|
| struct HdfMac80211STAOps \*staOps | Provides the interface set required for supporting the standalone (STA) mode.|
| struct HdfMac80211APOps \*apOps | Provides the interface set required for supporting the access point (AP) mode.|
2. Compile the configuration file to describe the devices supported by the driver. 2. Compile the configuration file to describe the devices supported by the driver.
...@@ -353,65 +349,68 @@ Implement the following APIs in the **HdfChipDriver**. ...@@ -353,65 +349,68 @@ Implement the following APIs in the **HdfChipDriver**.
The sample code is as follows: The sample code is as follows:
```
``` root {
root { wlan_config {
wlan_config { chip_name :& chipList {
chip_name :& chipList { chip_name :: chipInst {
chip_name :: chipInst { match_attr = "hdf_wlan_chips_chip_name"; /* Configure the matching attribute, which is used to provide the configuration root of the driver.*/
match_attr = "hdf_wlan_chips_chip_name"; /* Configure the matching attribute, which is used to provide the configuration root of the driver.*/ driverName = "driverName"; /* The value must be the same as that of driverName in HdfChipDriverFactory.*/
driverName = "driverName"; /* The value must be the same as that of driverName in HdfChipDriverFactory.*/ sdio {
sdio { vendorId = 0x0296;
vendorId = 0x0296; deviceId = [0x5347];
deviceId = [0x5347]; }
} }
} }
} }
} }
} ```
```
3. Edit the configuration file and load the driver. 3. Edit the configuration file and load the driver.
All device information about the product is defined in the **//vendor/MyProductVendor/MyProduct/config/device_info/device_info.hcs** file. Modify the file by adding configurations for the device named **device_wlan_chips** to the host named **network**. Note: The value of **moduleName** must be the same as that in the touchscreen driver. All device information about the product is defined in the **//vendor/MyProductVendor/MyProduct/config/device_info/device_info.hcs** file. Modify the file by adding configurations for the device named **device_wlan_chips** to the host named **network**.
Note: The value of **moduleName** must be the same as that in the touchscreen driver.
``` ```
deviceN :: deviceNode { deviceN :: deviceNode {
policy = 0; policy = 0;
preload = 2; preload = 2;
moduleName = "HDF_WLAN_CHIPS"; moduleName = "HDF_WLAN_CHIPS";
deviceMatchAttr = "hdf_wlan_chips_chip_name"; deviceMatchAttr = "hdf_wlan_chips_chip_name";
serviceName = "driverName"; serviceName = "driverName";
} }
``` ```
4. Build the driver. 4. Build the driver.
- Create a kernel configuration menu. Create a **Kconfig** file in the **//device/MySoCVendor/peripheral** directory. The file template is as follows: - Create a kernel configuration menu. Create a **Kconfig** file in the **//device/MySoCVendor/peripheral** directory. The file template is as follows:
```
config DRIVERS_WLAN_XXX
bool "Enable XXX WLAN Host driver"
default n
depends on DRIVERS_HDF_WIFI
help
Answer Y to enable XXX Host driver. Support chip xxx
```
``` Add the following configuration to the end of the **//drivers/hdf_core/adapter/khdf/linux/model/network/wifi/Kconfig** file:
config DRIVERS_WLAN_XXX
bool "Enable XXX WLAN Host driver"
default n
depends on DRIVERS_HDF_WIFI
help
Answer Y to enable XXX Host driver. Support chip xxx
```
Add the following sample code to the end of the **//drivers/adapter/khdf/linux/model/network/wifi/Kconfig** file to add the configuration menu to the kernel:
```
source "../../../../../device/MySoCVendor/peripheral/Kconfig"
```
``` - Create a build script.
source "../../../../../device/MySoCVendor/peripheral/Kconfig"
``` Add the following configuration to the end of the **//drivers/hdf_core/adapter/khdf/linux/model/network/wifi/Makefile** file:
- Create a build script.
Add the following configuration to the end of the **//drivers/adapter/khdf/linux/model/network/wifi/Makefile** file: ```
``` HDF_DEVICE_ROOT := $(HDF_DIR_PREFIX)/../device
HDF_DEVICE_ROOT := $(HDF_DIR_PREFIX)/../device obj-$(CONFIG_DRIVERS_WLAN_XXX) += $(HDF_DEVICE_ROOT)/MySoCVendor/peripheral/build/standard/
obj-$(CONFIG_DRIVERS_WLAN_XXX) += $(HDF_DEVICE_ROOT)/MySoCVendor/peripheral/build/standard/ ```
```
When **DRIVERS_WLAN_XXX** is enabled in the kernel, **makefile** in **//device/MySoCVendor/peripheral/build/standard/** is called. For details about the development, see [LED Peripheral Control](../guide/device-wlan-led-control.md).
When **DRIVERS_WLAN_XXX** is enabled in the kernel, **makefile** in **//device/MySoCVendor/peripheral/build/standard/** is called. For details about the development, see [LED Peripheral Control](../guide/device-wlan-led-control.md).
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册