mirror of
https://github.com/google/pebble.git
synced 2025-07-04 22:00:38 -04:00
Import of the watch repository from Pebble
This commit is contained in:
commit
3b92768480
10334 changed files with 2564465 additions and 0 deletions
40
applib-targets/sdl/examples/main.c
Normal file
40
applib-targets/sdl/examples/main.c
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright 2024 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "sdl_graphics.h"
|
||||
#include "sdl_app.h"
|
||||
|
||||
#include "applib/app.h"
|
||||
#include "applib/graphics/gtypes.h"
|
||||
#include "applib/graphics/graphics.h"
|
||||
#include "applib/graphics/graphics_line.h"
|
||||
|
||||
|
||||
int main(void) {
|
||||
GContext *context = sdl_graphics_get_gcontext();
|
||||
graphics_context_set_stroke_color(context, GColorBrightGreen);
|
||||
graphics_context_set_stroke_width(context, 2);
|
||||
graphics_draw_line(context, (GPoint){0, 0}, (GPoint){100, 100});
|
||||
graphics_draw_line(context, (GPoint){0, 10}, (GPoint){100, 10});
|
||||
graphics_draw_line(context, (GPoint){0, 20}, (GPoint){100, 20});
|
||||
graphics_draw_line(context, (GPoint){0, 30}, (GPoint){100, 30});
|
||||
graphics_draw_circle(context, (GPoint){50, 50}, 20);
|
||||
app_event_loop();
|
||||
|
||||
return 0;
|
||||
}
|
12
applib-targets/sdl/examples/wscript
Normal file
12
applib-targets/sdl/examples/wscript
Normal file
|
@ -0,0 +1,12 @@
|
|||
from waflib import Task
|
||||
from waflib.TaskGen import feature, before_method
|
||||
|
||||
|
||||
def build(bld):
|
||||
sources = bld.path.ant_glob('*.c')
|
||||
bld.program(source=sources,
|
||||
target='sdl-example',
|
||||
defines=['main=app_main'],
|
||||
use=['applib_sdl', 'fw_includes'])
|
||||
|
||||
# vim:filetype=python
|
72
applib-targets/sdl/sdl_app.c
Normal file
72
applib-targets/sdl/sdl_app.c
Normal file
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright 2024 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "sdl_app.h"
|
||||
#include "sdl_graphics.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
extern int app_main(void);
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (!sdl_app_init()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
app_main();
|
||||
sdl_app_deinit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
bool sdl_app_init(void) {
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
printf("Error: Failed to init SDL\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!sdl_graphics_init()) {
|
||||
printf("Error: Failed to init graphics\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void sdl_app_deinit(void) {
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
void sdl_app_event_loop(void) {
|
||||
SDL_Event event;
|
||||
int keypress = 0;
|
||||
|
||||
while (!keypress) {
|
||||
sdl_graphics_render();
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_QUIT:
|
||||
keypress = 1;
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
keypress = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
23
applib-targets/sdl/sdl_app.h
Normal file
23
applib-targets/sdl/sdl_app.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright 2024 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
bool sdl_app_init(void);
|
||||
void sdl_app_deinit(void);
|
||||
void sdl_app_event_loop(void);
|
61
applib-targets/sdl/sdl_graphics.c
Normal file
61
applib-targets/sdl/sdl_graphics.c
Normal file
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright 2024 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "sdl_graphics.h"
|
||||
|
||||
#include "applib/graphics/graphics.h"
|
||||
#include "applib/graphics/8_bit/framebuffer.h"
|
||||
#include "util/circular_cache.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <SDL.h>
|
||||
|
||||
static GContext s_gcontext = {};
|
||||
static FrameBuffer fb = {};
|
||||
static SDL_Surface *screen = NULL;
|
||||
|
||||
bool sdl_graphics_init(void) {
|
||||
if (!(screen = SDL_SetVideoMode(DISP_COLS, DISP_ROWS, 8 /* bits/pixel */, SDL_HWSURFACE))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
framebuffer_init(&fb, &(GSize) {DISP_COLS, DISP_ROWS});
|
||||
s_gcontext = (GContext) {
|
||||
.dest_bitmap = (GBitmap) {
|
||||
.addr = screen->pixels,
|
||||
.row_size_bytes = DISP_COLS,
|
||||
.info = (BitmapInfo) {.format = GBITMAP_NATIVE_FORMAT },
|
||||
.bounds = (GRect) { { 0, 0 }, { DISP_COLS, DISP_ROWS } },
|
||||
.data_row_infos = NULL,
|
||||
},
|
||||
.parent_framebuffer = &fb,
|
||||
.parent_framebuffer_vertical_offset = 0,
|
||||
.lock = false
|
||||
};
|
||||
|
||||
graphics_context_set_default_drawing_state(&s_gcontext, GContextInitializationMode_App);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
GContext *sdl_graphics_get_gcontext(void) {
|
||||
return &s_gcontext;
|
||||
}
|
||||
|
||||
void sdl_graphics_render(void) {
|
||||
SDL_Flip(screen);
|
||||
}
|
24
applib-targets/sdl/sdl_graphics.h
Normal file
24
applib-targets/sdl/sdl_graphics.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright 2024 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "applib/graphics/gtypes.h"
|
||||
|
||||
bool sdl_graphics_init(void);
|
||||
void sdl_graphics_render(void);
|
||||
GContext *sdl_graphics_get_gcontext(void);
|
105
applib-targets/sdl/shims.c
Normal file
105
applib-targets/sdl/shims.c
Normal file
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
* Copyright 2024 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "util/heap.h"
|
||||
#include "util/circular_cache.h"
|
||||
|
||||
#include "sdl_app.h"
|
||||
#include "sdl_graphics.h"
|
||||
|
||||
void *task_malloc(size_t bytes) {
|
||||
return malloc(bytes);
|
||||
}
|
||||
|
||||
void task_free(void *ptr) {
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
void app_log(uint8_t log_level, const char* src_filename,
|
||||
int src_line_number, const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vprintf(fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
GContext* app_state_get_graphics_context() {
|
||||
return sdl_graphics_get_gcontext();
|
||||
}
|
||||
|
||||
Heap *app_state_get_heap(void) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GBitmap* app_state_legacy2_get_2bit_framebuffer(void) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void circular_cache_init(CircularCache* c, uint8_t* buffer, size_t item_size,
|
||||
int total_items, Comparator compare_cb) {
|
||||
}
|
||||
|
||||
bool heap_is_allocated(Heap* const heap, void* ptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void passert_failed(const char* filename, int line_number, const char* message, ...) {
|
||||
}
|
||||
|
||||
void passert_failed_no_message(const char* filename, int line_number) {
|
||||
}
|
||||
|
||||
void pbl_log(uint8_t log_level, const char* src_filename,
|
||||
int src_line_number, const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vprintf(fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
bool process_manager_compiled_with_legacy2_sdk(void) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ResAppNum sys_get_current_resource_num(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const uint8_t * sys_resource_builtin_bytes(ResAppNum app_num, uint32_t resource_id,
|
||||
uint32_t *num_bytes_out) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t sys_resource_load_range(ResAppNum app_num, uint32_t id, uint32_t start_bytes,
|
||||
uint8_t *buffer, size_t num_bytes) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t sys_resource_size(ResAppNum app_num, uint32_t handle) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void app_event_loop(void) {
|
||||
sdl_app_event_loop();
|
||||
}
|
||||
|
||||
void wtf(void) {
|
||||
printf(">>> WTF\n");
|
||||
}
|
27
applib-targets/sdl/wscript
Normal file
27
applib-targets/sdl/wscript
Normal file
|
@ -0,0 +1,27 @@
|
|||
import waflib
|
||||
|
||||
|
||||
def configure(conf):
|
||||
conf.check_cfg(msg='Checking for sdl-config',
|
||||
path='sdl-config',
|
||||
package='',
|
||||
args='--cflags --libs',
|
||||
uselib_store='SDL')
|
||||
|
||||
conf.find_program('objcopy gobjcopy', var='OBJCOPY')
|
||||
|
||||
# We are overriding the gcc toolchain include/time.h with our own
|
||||
# just to check/force our version of <time.h>
|
||||
conf.env.CFLAGS.append('-D_TIME_H_')
|
||||
|
||||
|
||||
def build(bld):
|
||||
sources = bld.path.ant_glob('*.c')
|
||||
bld.stlib(source=sources,
|
||||
target='applib_sdl',
|
||||
includes='.',
|
||||
export_includes='.',
|
||||
use=['applib', 'fw_includes', 'libutil', 'upng', 'SDL'])
|
||||
bld.recurse('examples')
|
||||
|
||||
# vim:filetype=python
|
Loading…
Add table
Add a link
Reference in a new issue