Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bsp: New BSP for M5Core2 (BSP-514) #344

Merged
merged 6 commits into from
Sep 4, 2024

Conversation

Tinyu-Zhao
Copy link
Contributor

@Tinyu-Zhao Tinyu-Zhao commented Jul 1, 2024

ESP-BSP Pull Request checklist

Note: For new BSPs create a PR with this link.

  • Version of modified component bumped
  • CI passing

Change description

New BSP for M5Core2

@CLAassistant
Copy link

CLAassistant commented Jul 1, 2024

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot changed the title bsp: New BSP for M5Core2 bsp: New BSP for M5Core2 (BSP-514) Jul 1, 2024
@Tinyu-Zhao
Copy link
Contributor Author

@tore-espressif PTAL🙏

Copy link
Collaborator

@espzav espzav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thank you for this PR. I made the first round of the review and put some comments.
One additional thing:

  1. Please, could you add default sdkconfigs (sdkconfig.bsp.m5stack_core_2) to relevant examples?
  2. I tried display_audio_photo example after some minor changes (disabled microphone) and the speaker is not working - audio file is not playing.
    Here is patch of my changes in example. We can push it too.
    audio_photo_disable_patch.txt

I will continue with review tomorrow.

.github/workflows/upload_component_noglib.yml Outdated Show resolved Hide resolved
SquareLine/boards/v9/m5stack_core_2/main/idf_component.yml Outdated Show resolved Hide resolved
@Tinyu-Zhao
Copy link
Contributor Author

Tinyu-Zhao commented Jul 3, 2024

Hi, thank you for this PR. I made the first round of the review and put some comments. One additional thing:

  1. Please, could you add default sdkconfigs (sdkconfig.bsp.m5stack_core_2) to relevant examples?
  2. I tried display_audio_photo example after some minor changes (disabled microphone) and the speaker is not working - audio file is not playing.
    Here is patch of my changes in example. We can push it too.
    audio_photo_disable_patch.txt

I will continue with review tomorrow.

I will add the default sdkconfigs of m5core2. When I tested the audio, I tried to modify it based on the display_main.txt example, speaker work fine. I will try to check what went wrong, you can also try my modified display_main.c. Thank you for your help.

@Tinyu-Zhao
Copy link
Contributor Author

Tinyu-Zhao commented Jul 3, 2024

I think the problem may be here, Core2's amplifier is using NS4168.
There is no need to use I2C for control, just input the audio signal directly through I2S.

I'm initialising I2C here because the speaker enable pin is controlled by the AXP192/AXP2101 for I2C communication

Core2 SCH
Core2 V1.1 SCH

I'm sorry, but this is an amplifier chip from a Chinese manufacturer, and they don't seem to provide the datasheet in English.

bsp/m5stack_core_2/include/bsp/m5stack_core_2.h Outdated Show resolved Hide resolved
bsp/m5stack_core_2/m5stack_core_2.c Outdated Show resolved Hide resolved
bsp/m5stack_core_2/m5stack_core_2.c Outdated Show resolved Hide resolved
bsp/m5stack_core_2/m5stack_core_2.c Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
bsp/m5stack_core_2/m5stack_core_2.c Outdated Show resolved Hide resolved
bsp/m5stack_core_2/m5stack_core_2_idf5.c Outdated Show resolved Hide resolved
bsp/m5stack_core_2/m5stack_core_2_idf5.c Outdated Show resolved Hide resolved
bsp/m5stack_core_2/m5stack_core_2_idf5.c Outdated Show resolved Hide resolved
bsp/m5stack_core_2/m5stack_core_2.c Outdated Show resolved Hide resolved
@espzav
Copy link
Collaborator

espzav commented Jul 3, 2024

@Tinyu-Zhao I tested the example from you and it is working fine. But the function bsp_get_i2s_tx_chan() is not right BSP API - it should be removed. We are using only esp_codec_dev. The display_audio_photo is working for all boards with audio. It should work with Core2 too. There must be something wrong. I am looking for what is wrong.

@Tinyu-Zhao
Copy link
Contributor Author

@Tinyu-Zhao I tested the example from you and it is working fine. But the function bsp_get_i2s_tx_chan() is not right BSP API - it should be removed. We are using only esp_codec_dev. The display_audio_photo is working for all boards with audio. It should work with Core2 too. There must be something wrong. I am looking for what is wrong.

I think Core2 is similar to this board, which does not use I2C controlled power amplifier chip, but the sdkconfig of this board does not seem to appear in "display_audio_photo".

@espzav
Copy link
Collaborator

espzav commented Jul 4, 2024

I think Core2 is similar to this board, which does not use I2C controlled power amplifier chip, but the sdkconfig of this board does not seem to appear in "display_audio_photo".

Mentioned board has ESP32C3 chip, which has limited RAM size and the display_audio_photo need more modifications for this board. And this board has rounded LCD screen - this example is not good for rounded screen.
I made some small changes and tested audio with this board and it is working properly with this example.

@Tinyu-Zhao
Copy link
Contributor Author

I think Core2 is similar to this board, which does not use I2C controlled power amplifier chip, but the sdkconfig of this board does not seem to appear in "display_audio_photo".

Mentioned board has ESP32C3 chip, which has limited RAM size and the display_audio_photo need more modifications for this board. And this board has rounded LCD screen - this example is not good for rounded screen. I made some small changes and tested audio with this board and it is working properly with this example.

🤔That’s a little weird.

@espzav
Copy link
Collaborator

espzav commented Jul 4, 2024

🤔That’s a little weird.

Yes, today, I tried lot of settings and combinations and it is still not working. I am sorry, I will continue next week.

@tore-espressif
Copy link
Collaborator

@Tinyu-Zhao we usually resolve the review discussions only after the fixed code has been pushed to GitHub.

Do you have any local updates that you could push?

@Tinyu-Zhao
Copy link
Contributor Author

@Tinyu-Zhao we usually resolve the review discussions only after the fixed code has been pushed to GitHub.

Do you have any local updates that you could push?

Yes, there are many. I thought that pushing them one by one might disturb you, so I thought about merging them. I will push the modified parts now. Thank you.

@tore-espressif
Copy link
Collaborator

Yes, there are many. I thought that pushing them one by one might disturb you, so I thought about merging them. I will push the modified parts now. Thank you.

Sounds reasonable to me! thanks

@tore-espressif
Copy link
Collaborator

@Tinyu-Zhao In the mean time, here's a quick fix for audio playback m5stack#3 together with description of the proposed solution

@Tinyu-Zhao
Copy link
Contributor Author

With the help of @tore-espressif, the Core2 speaker works successfully, thank you.
But I still can't find the right place to put the AXP initialization code related to Vibration motor and Battery. @espzav and @tore-espressif, do you have any suggestions?
Most of our hosts are based on AXP192 and AXP2101. If more m5stack devices are added to the bsp later, the messy axp initialization code may affect the beauty of the project.

@espzav
Copy link
Collaborator

espzav commented Aug 6, 2024

With the help of @tore-espressif, the Core2 speaker works successfully, thank you. But I still can't find the right place to put the AXP initialization code related to Vibration motor and Battery. @espzav and @tore-espressif, do you have any suggestions? Most of our hosts are based on AXP192 and AXP2101. If more m5stack devices are added to the bsp later, the messy axp initialization code may affect the beauty of the project.

@tore-espressif @Tinyu-Zhao I was thinking about it and I would like to add new API function somethink like bsp_feature_enable(bsp_feature_t feature, bool enable); What do you think about it? We can consider it in all BSPs, which will need it. This function will be for all features (LCD, touch, SD card, Vibration, ...). In some cases it will be called inside BPS (LCD, Touch, SD card). In other cases, it can be called by user.

@Tinyu-Zhao
Copy link
Contributor Author

With the help of @tore-espressif, the Core2 speaker works successfully, thank you. But I still can't find the right place to put the AXP initialization code related to Vibration motor and Battery. @espzav and @tore-espressif, do you have any suggestions? Most of our hosts are based on AXP192 and AXP2101. If more m5stack devices are added to the bsp later, the messy axp initialization code may affect the beauty of the project.

@tore-espressif @Tinyu-Zhao I was thinking about it and I would like to add new API function somethink like bsp_feature_enable(bsp_feature_t feature, bool enable); What do you think about it? We can consider it in all BSPs, which will need it. This function will be for all features (LCD, touch, SD card, Vibration, ...). In some cases it will be called inside BPS (LCD, Touch, SD card). In other cases, it can be called by user.

I think it's a good idea to give users more flexibility to control device peripherals.

Copy link
Collaborator

@espzav espzav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, why there is not implemented microphone? The board has it, right?

examples/display_audio_photo/main/idf_component.yml Outdated Show resolved Hide resolved
@rashedtalukder
Copy link

The mic and speaker on the Core2 share a pin. You have to disable one to enable another: https://github.com/m5stack/Core2-for-AWS-IoT-Kit/blob/BSP-dev/lib/audio/core2foraws_audio.c

@rashedtalukder
Copy link

rashedtalukder commented Aug 6, 2024

What is the plan here for the IMU and the external i2c port? @espzav @tore-espressif @Tinyu-Zhao, here's no protection in this BSP to prevent simultaneous access from different threads to different i2c devices on the same bus. I didn't see it in the Core3 example either.

@Tinyu-Zhao
Copy link
Contributor Author

Please, why there is not implemented microphone? The board has it, right?

That's right, but the Core2 microphone is on the expansion board instead of the host. When the user replaces the Core2 base, the Mic will no longer be valid. We plan to only support peripherals on the host body.

image

@tore-espressif
Copy link
Collaborator

here's no protection in this BSP to prevent simultaneous access from different threads to different i2c devices on the same bus. I didn't see it in the Core3 example either.

This is implemented in the I2C driver itself; in esp-idf. If you call I2C master API from different threads (e.g. drivers), they will be executed one after the other. So we don't implement any other protection mechanism in the BSPs. Have you encountered any issues regarding this?

@espzav
Copy link
Collaborator

espzav commented Aug 14, 2024

@Tinyu-Zhao please, could you change feature initialization (bsp_feature_enable(bsp_feature_t feature, bool enable);) before next round of my review? Or do you need any help?

@Tinyu-Zhao
Copy link
Contributor Author

@Tinyu-Zhao please, could you change feature initialization (bsp_feature_enable(bsp_feature_t feature, bool enable);) before next round of my review? Or do you need any help?

I have modified the feature function as follows🙏

@espzav
Copy link
Collaborator

espzav commented Aug 15, 2024

@Tinyu-Zhao please, could you change feature initialization (bsp_feature_enable(bsp_feature_t feature, bool enable);) before next round of my review? Or do you need any help?

I have modified the feature function as follows🙏

Thank you. I am sorry, I thought a little different.

  1. Move structure bsp_feature_t to m5stack_core_2.h
  2. add bsp_feature_enable to m5stack_core_2.h
  3. remove static from bsp_feature_enable
  4. add vibration and battery to this function too

I dont't like initialization of battery and vibration in bsp_display_brightness_init.

Do you see what I mean?

@Tinyu-Zhao
Copy link
Contributor Author

@Tinyu-Zhao please, could you change feature initialization (bsp_feature_enable(bsp_feature_t feature, bool enable);) before next round of my review? Or do you need any help?

I have modified the feature function as follows🙏

Thank you. I am sorry, I thought a little different.

  1. Move structure bsp_feature_t to m5stack_core_2.h
  2. add bsp_feature_enable to m5stack_core_2.h
  3. remove static from bsp_feature_enable
  4. add vibration and battery to this function too

I dont't like initialization of battery and vibration in bsp_display_brightness_init.

Do you see what I mean?

OK, I understand, I will continue working tomorrow

@Tinyu-Zhao
Copy link
Contributor Author

@Tinyu-Zhao please, could you change feature initialization (bsp_feature_enable(bsp_feature_t feature, bool enable);) before next round of my review? Or do you need any help?

I have modified the feature function as follows🙏

Thank you. I am sorry, I thought a little different.

  1. Move structure bsp_feature_t to m5stack_core_2.h
  2. add bsp_feature_enable to m5stack_core_2.h
  3. remove static from bsp_feature_enable
  4. add vibration and battery to this function too

I dont't like initialization of battery and vibration in bsp_display_brightness_init.

Do you see what I mean?

I have made the modifications as required, please check

@tore-espressif
Copy link
Collaborator

@Tinyu-Zhao thanks for all the work! Please resolve all conflicts, so we can go ahead with merge

@Tinyu-Zhao
Copy link
Contributor Author

@tore-espressif, All conflicts have been resolved, please help to review them.

@tore-espressif
Copy link
Collaborator

@tore-espressif, All conflicts have been resolved, please help to review them.

LGTM! Let's wait for @espzav , he should be back from vacation next week

Copy link
Collaborator

@espzav espzav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some nitpick comments. Otherwise LGTM

  • please rebase master branch

SquareLine/boards/v9/m5stack_core_2/main/idf_component.yml Outdated Show resolved Hide resolved
bsp/m5stack_core_2/include/bsp/m5stack_core_2.h Outdated Show resolved Hide resolved
@Tinyu-Zhao
Copy link
Contributor Author

@espzav I have completed error correction and rebasing, please review.

@Tinyu-Zhao
Copy link
Contributor Author

Tinyu-Zhao commented Sep 4, 2024 via email

@tore-espressif tore-espressif merged commit 7e2be83 into espressif:master Sep 4, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants