-
Notifications
You must be signed in to change notification settings - Fork 106
Update screen to YWF
#561
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
Merged
+185
−119
Merged
Update screen to YWF
#561
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,173 +1,155 @@ | ||
| #include <libtock/defer.h> | ||
| #include <libtock/display/screen.h> | ||
| #include <libtock/display/syscalls/screen_syscalls.h> | ||
|
|
||
| #include "screen.h" | ||
|
|
||
| struct screen_done { | ||
| returncode_t ret; | ||
| bool fired; | ||
| }; | ||
| struct screen_format { | ||
| libtock_screen_format_t format; | ||
| returncode_t ret; | ||
| bool fired; | ||
| }; | ||
| struct screen_rotation { | ||
| int rotation; | ||
| returncode_t ret; | ||
| bool fired; | ||
| }; | ||
| static returncode_t screen_set_color(uint8_t* buffer, int buffer_len, int position, size_t color) { | ||
| // TODO color mode | ||
| if (position < buffer_len - 2) { | ||
| buffer[position * 2] = (color >> 8) & 0xFF; | ||
| buffer[position * 2 + 1] = color & 0xFF; | ||
| return RETURNCODE_SUCCESS; | ||
| } else { | ||
| return RETURNCODE_ESIZE; | ||
| } | ||
| } | ||
|
|
||
| static struct screen_done result; | ||
| static struct screen_format result_format; | ||
| static struct screen_rotation result_rotation; | ||
|
|
||
| bool libtocksync_screen_exists(void) { | ||
| return libtock_screen_driver_exists(); | ||
| } | ||
|
|
||
| static void screen_cb_done(returncode_t ret) { | ||
| result.ret = ret; | ||
| result.fired = true; | ||
| statuscode_t libtocksync_screen_buffer_init(size_t len, uint8_t** buffer) { | ||
| return libtock_screen_buffer_init(len, buffer); | ||
| } | ||
|
|
||
| static void screen_cb_format(returncode_t ret, libtock_screen_format_t format) { | ||
| result_format.ret = ret; | ||
| result_format.format = format; | ||
| result_format.fired = true; | ||
| returncode_t libtocksync_screen_get_supported_resolutions(uint32_t* resolutions) { | ||
| return libtock_screen_get_supported_resolutions(resolutions); | ||
| } | ||
|
|
||
| static void screen_cb_rotation(returncode_t ret, libtock_screen_rotation_t rotation) { | ||
| result_rotation.ret = ret; | ||
| result_rotation.rotation = rotation; | ||
| result_rotation.fired = true; | ||
| returncode_t libtocksync_screen_get_supported_resolution(size_t index, uint32_t* width, uint32_t* height) { | ||
| return libtock_screen_get_supported_resolution(index, width, height); | ||
| } | ||
|
|
||
| bool libtocksync_screen_exists(void) { | ||
| return libtock_screen_driver_exists(); | ||
| returncode_t libtocksync_screen_get_supported_pixel_formats(uint32_t* formats) { | ||
| return libtock_screen_get_supported_pixel_formats(formats); | ||
| } | ||
|
|
||
| returncode_t libtocksync_screen_get_supported_pixel_format(size_t index, libtock_screen_format_t* format) { | ||
| return libtock_screen_get_supported_pixel_format(index, format); | ||
| } | ||
|
|
||
| int libtocksync_screen_get_bits_per_pixel(libtock_screen_format_t format) { | ||
| return libtock_screen_get_bits_per_pixel(format); | ||
| } | ||
|
|
||
|
|
||
| returncode_t libtocksync_screen_set_brightness(uint32_t brightness) { | ||
| returncode_t ret; | ||
|
|
||
| result.fired = false; | ||
|
|
||
| ret = libtock_screen_set_brightness(brightness, screen_cb_done); | ||
| ret = libtock_screen_command_set_brightness(brightness); | ||
| if (ret != RETURNCODE_SUCCESS) return ret; | ||
|
|
||
| // Wait for the callback. | ||
| yield_for(&result.fired); | ||
| return result.ret; | ||
| ret = libtocksync_screen_yield_wait_for(); | ||
| return ret; | ||
| } | ||
|
|
||
| returncode_t libtocksync_screen_invert_on(void) { | ||
| returncode_t ret; | ||
|
|
||
| result.fired = false; | ||
|
|
||
| ret = libtock_screen_invert_on(screen_cb_done); | ||
| ret = libtock_screen_command_invert_on(); | ||
| if (ret != RETURNCODE_SUCCESS) return ret; | ||
|
|
||
| // Wait for the callback. | ||
| yield_for(&result.fired); | ||
| return result.ret; | ||
| ret = libtocksync_screen_yield_wait_for(); | ||
| return ret; | ||
| } | ||
|
|
||
| returncode_t libtocksync_screen_invert_off(void) { | ||
| returncode_t ret; | ||
|
|
||
| result.fired = false; | ||
|
|
||
| ret = libtock_screen_invert_on(screen_cb_done); | ||
| ret = libtock_screen_command_invert_off(); | ||
| if (ret != RETURNCODE_SUCCESS) return ret; | ||
|
|
||
| // Wait for the callback. | ||
| yield_for(&result.fired); | ||
| return result.ret; | ||
| ret = libtocksync_screen_yield_wait_for(); | ||
| return ret; | ||
| } | ||
|
|
||
| returncode_t libtocksync_screen_get_pixel_format(libtock_screen_format_t* format) { | ||
| returncode_t ret; | ||
|
|
||
| result_format.fired = false; | ||
|
|
||
| ret = libtock_screen_get_pixel_format(screen_cb_format); | ||
| ret = libtock_screen_command_get_pixel_format(); | ||
| if (ret != RETURNCODE_SUCCESS) return ret; | ||
|
|
||
| // Wait for the callback. | ||
| yield_for(&result_format.fired); | ||
| if (result_format.ret != RETURNCODE_SUCCESS) return result_format.ret; | ||
| ret = libtocksync_screen_yield_wait_for_format(format); | ||
| return ret; | ||
| } | ||
|
|
||
| *format = result_format.format; | ||
| return RETURNCODE_SUCCESS; | ||
| returncode_t libtocksync_screen_get_resolution(uint32_t* width, uint32_t* height) { | ||
| return libtock_screen_command_get_resolution(width, height); | ||
| } | ||
|
|
||
| returncode_t libtocksync_screen_get_rotation(libtock_screen_rotation_t* rotation) { | ||
| returncode_t ret; | ||
|
|
||
| result_rotation.fired = false; | ||
|
|
||
| ret = libtock_screen_get_rotation(screen_cb_rotation); | ||
| ret = libtock_screen_command_get_rotation(); | ||
| if (ret != RETURNCODE_SUCCESS) return ret; | ||
|
|
||
| // Wait for the callback. | ||
| yield_for(&result_rotation.fired); | ||
| if (result_rotation.ret != RETURNCODE_SUCCESS) return result_rotation.ret; | ||
|
|
||
| *rotation = result_rotation.rotation; | ||
| return RETURNCODE_SUCCESS; | ||
| ret = libtocksync_screen_yield_wait_for_rotation(rotation); | ||
| return ret; | ||
| } | ||
|
|
||
| returncode_t libtocksync_screen_set_rotation(libtock_screen_rotation_t rotation) { | ||
| returncode_t ret; | ||
|
|
||
| result.fired = false; | ||
|
|
||
| ret = libtock_screen_set_rotation(rotation, screen_cb_done); | ||
| ret = libtock_screen_command_set_rotation(rotation); | ||
| if (ret != RETURNCODE_SUCCESS) return ret; | ||
|
|
||
| // Wait for the callback. | ||
| yield_for(&result.fired); | ||
| return result.ret; | ||
| ret = libtocksync_screen_yield_wait_for(); | ||
| return ret; | ||
| } | ||
|
|
||
| returncode_t libtocksync_screen_set_frame(uint16_t x, uint16_t y, uint16_t width, uint16_t height) { | ||
| returncode_t ret; | ||
|
|
||
| result.fired = false; | ||
|
|
||
| ret = libtock_screen_set_frame(x, y, width, height, screen_cb_done); | ||
| ret = libtock_screen_command_set_frame(x, y, width, height); | ||
| if (ret != RETURNCODE_SUCCESS) return ret; | ||
|
|
||
| // Wait for the callback. | ||
| yield_for(&result.fired); | ||
| return result.ret; | ||
| ret = libtocksync_screen_yield_wait_for(); | ||
| return ret; | ||
| } | ||
|
|
||
| returncode_t libtocksync_screen_fill(uint8_t* buffer, int buffer_len, size_t color) { | ||
| returncode_t ret; | ||
|
|
||
| result.fired = false; | ||
| ret = screen_set_color(buffer, buffer_len, 0, color); | ||
| if (ret != RETURNCODE_SUCCESS) return ret; | ||
|
|
||
| ret = libtock_screen_set_readonly_allow(buffer, buffer_len); | ||
| if (ret != RETURNCODE_SUCCESS) return ret; | ||
| defer { libtock_screen_set_readonly_allow(NULL, 0); | ||
| } | ||
|
|
||
| ret = libtock_screen_fill(buffer, buffer_len, color, screen_cb_done); | ||
| ret = libtock_screen_command_fill(); | ||
| if (ret != RETURNCODE_SUCCESS) return ret; | ||
|
|
||
| // Wait for the callback. | ||
| yield_for(&result.fired); | ||
| if (result.ret != RETURNCODE_SUCCESS) return result.ret; | ||
| ret = libtocksync_screen_yield_wait_for(); | ||
|
|
||
| ret = libtock_screen_set_readonly_allow(NULL, 0); | ||
| return ret; | ||
| } | ||
|
|
||
| returncode_t libtocksync_screen_write(uint8_t* buffer, int buffer_len, size_t length) { | ||
| returncode_t ret; | ||
|
|
||
| result.fired = false; | ||
| ret = libtock_screen_set_readonly_allow(buffer, buffer_len); | ||
| if (ret != RETURNCODE_SUCCESS) return ret; | ||
| defer { libtock_screen_set_readonly_allow(NULL, 0); | ||
| } | ||
|
|
||
| ret = libtock_screen_write(buffer, buffer_len, length, screen_cb_done); | ||
| ret = libtock_screen_command_write(length); | ||
| if (ret != RETURNCODE_SUCCESS) return ret; | ||
|
|
||
| // Wait for the callback. | ||
| yield_for(&result.fired); | ||
| if (result.ret != RETURNCODE_SUCCESS) return result.ret; | ||
| ret = libtocksync_screen_yield_wait_for(); | ||
|
|
||
| ret = libtock_screen_set_readonly_allow(NULL, 0); | ||
| return ret; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.