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

Lab2A Sudong Wang work with Sizhe Ma, Ying Xu #71

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,45 @@ University of Pennsylvania, ESE 5190: Intro to Embedded Systems, Lab 2A
(TODO) YOUR NAME HERE
(TODO) LinkedIn, personal website, twitter, etc.
Tested on: (TODO) MacBook Pro (14-inch, 2021), macOS Monterey 12.5.1
(TODO) Sudong wang
(TODO) [email protected]
Tested on: (TODO) Dell XPS 13

(TODO: Your README)
# lab write up
# 3.2 Annotated code
![4f6a6353263aae223d7f1a7b952589a](https://user-images.githubusercontent.com/113209201/196401858-9d49b5d2-d75b-4555-83e9-dd48ee00708b.jpg)
![e76ba3b023e2d75f51e35df7dfe73ed](https://user-images.githubusercontent.com/113209201/196401872-2410786e-a759-4217-b8df-131a59af1992.jpg)
![6dcad8c06a34ab0f9de09fcd8f404be](https://user-images.githubusercontent.com/113209201/196401891-1d751f45-0a97-4840-8b6f-ace2a364ba9d.jpg)
![b3fc9b2fb08b10bcead345cc93b7ded](https://user-images.githubusercontent.com/113209201/196402867-bc67871a-0168-4371-ba8c-b1f675ff928a.jpg)

Include lab questions, screenshots, analysis, etc. (Remember, this is public, so don't put anything here you don't want to share with the world.)
# 3.4 spread sheet
![4b79b4945d25a41980f3ab08dcce67b](https://user-images.githubusercontent.com/113209201/196401935-fe56020e-141b-4546-9d0b-01a89f85f93f.jpg)

# 3.5 paper model
![fc7efd4dfa9325e9d917fdd74714d2c](https://user-images.githubusercontent.com/113209201/196401975-1db43aea-cd58-411d-a7ab-7a4503680296.jpg)
![f7c56668b91fc16e9577ff7c5d8541d](https://user-images.githubusercontent.com/113209201/196402005-6227246c-9303-4a68-a4ce-9b9c79d3a583.jpg)


# decision we made
Before the modeling, I am not confident with the coding, so we look up to the datasheet and find out the meaning of each line of coding. Finally, we choose green as the color as do the following modeling. The code we use is below:
https://github.com/sudong-wang/ese5190-2022-lab2-into-the-void-star/blob/main/code(2).txt

# 3.6 transmission spreadsheet & 3.7 time diagram
![a22b48994d02aeb2971234b711fa02b](https://user-images.githubusercontent.com/113209201/196409415-258fef86-8e38-4abe-903b-32fd86d52118.jpg)



# part 4
![WeChat_20221018033724 (1)](https://user-images.githubusercontent.com/113209201/196409324-724e298f-e7f4-401a-8444-a17e7222ec19.gif)
The code:

https://github.com/sudong-wang/ese5190-2022-lab2-into-the-void-star/tree/main/p4
# Feedback

# Reflection on Tools
The paper is easy to use but time consuming, and the spread sheet is clear to use though it is hard to learn. I would personally use coding to make the timing diagram, though it may not be easy to configure.

# Comments
Junpeng Zhao's work help us with problem 3.7
Also, it would be better if we are given the lab ahead of time each week, and it is great that the lab introduction is thorough and considerate, it is also a little long to read and hard to find what we need to do.
Binary file added WeChat_20221018033724 (1).gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
135 changes: 135 additions & 0 deletions code(2).txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/**
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <stdio.h> // standard c library
#include <stdlib.h> // standard c library

#include "pico/stdlib.h" // standard c librarry from pico
#include "hardware/pio.h" // chip specific library
#include "hardware/clocks.h" // chip specific library
#include "ws2812.pio.h" //Autogenerated library from pioasm

#define IS_RGBW true //RGB input
#define NUM_PIXELS 150 //Number of Ws2812

#ifdef PICO_DEFAULT_WS2812_PIN //default signal pin of the LED
#define WS2812_PIN PICO_DEFAULT_WS2812_PIN // default signal pin of LED
#else
// default to pin 2 if the board doesn't have a default WS2812 pin defined
#define WS2812_PIN 2
#endif

static inline void put_pixel(uint32_t pixel_grb) { //wait for FIFO
pio_sm_put_blocking(pio0, 0, pixel_grb << 8u);
}

static inline uint32_t urgb_u32(uint8_t r, uint8_t g, uint8_t b) { // convert RGB to GRB
return
((uint32_t) (r) << 8) |
((uint32_t) (g) << 16) |
(uint32_t) (b);
}

void pattern_snakes(uint len, uint t) { // create a flashing mode called snakes
for (uint i = 0; i < len; ++i) {
uint x = (i + (t >> 1)) % 64;
if (x < 10)
put_pixel(urgb_u32(0xff, 0, 0));
else if (x >= 15 && x < 25)
put_pixel(urgb_u32(0, 0xff, 0));
else if (x >= 30 && x < 40)
put_pixel(urgb_u32(0, 0, 0xff));
else
put_pixel(0);
}
}

void pattern_random(uint len, uint t) { // create a flashing mode called random
if (t % 8)
return;
for (int i = 0; i < len; ++i)
put_pixel(rand());
}

void pattern_sparkle(uint len, uint t) { // create a flashing mode called sparkle
if (t % 8)
return;
for (int i = 0; i < len; ++i)
put_pixel(rand() % 16 ? 0 : 0xffffffff);
}

void pattern_greys(uint len, uint t) { // create a flashing mode called greys
int max = 100; // let's not draw too much current!
t %= max;
for (int i = 0; i < len; ++i) {
put_pixel(t * 0x10101);
if (++t >= max) t = 0;
}
}

typedef void (*pattern)(uint len, uint t);
const struct {
pattern pat;
const char *name;
} pattern_table[] = {
{pattern_snakes, "Snakes!"},
{pattern_random, "Random data"},
{pattern_sparkle, "Sparkles"},
{pattern_greys, "Greys"},
};

// int main() {
// //set_sys_clock_48();
// stdio_init_all(); // initialize the board
// printf("WS2812 Smoke Test, using pin %d", WS2812_PIN); //print the pin number of LED

// // todo get free sm
// PIO pio = pio0; // select Pio module number
// int sm = 0; // select state machine number
// uint offset = pio_add_program(pio, &ws2812_program);

// ws2812_program_init(pio, sm, offset, WS2812_PIN, 800000, IS_RGBW);

// int t = 0; // Let different modes cycle
// while (1) {
// for(int i=0;i<=220;i=i+4){
// printf("address:%08x,%08x/n",(int*)(0x50200000+i),*((int*)0x5020000+i));
// }
// int pat = rand() % count_of(pattern_table);
// int dir = (rand() >> 30) & 1 ? 1 : -1;
// puts(pattern_table[pat].name);
// puts(dir == 1 ? "(forward)" : "(backward)");
// for (int i = 0; i < 1000; ++i) {
// pattern_table[pat].pat(NUM_PIXELS, t);
// sleep_ms(10);
// t += dir;
// }
// }
// sleep_ms (10000);
// }

// print the value of the register
int main(){
uint32_t grb = 0x00FF00; //blue
int *rgtr = 0x50200000;
PIO pio = pio0; // select Pio module number
int sm = 0; // select state machine number
uint offset = pio_add_program(pio, &ws2812_program);
while (1)
{
stdio_init_all();
printf("the value of registers used in PIO 0 \n");
ws2812_program_init(pio, sm, offset, WS2812_PIN, 800000, IS_RGBW);
// put_pixel(grb);
for (int i = 0; i < 81; i++)
{
printf("%08x, \tvalue = %08x \n", rgtr+i, *(rgtr+i));
}
sleep_ms(5000);
}

return 0;
}
33 changes: 33 additions & 0 deletions p4/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
cmake_minimum_required(VERSION 3.12)

# Pull in SDK (must be before project)
include(pico_sdk_import.cmake)

project(pico_examples C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

if (PICO_SDK_VERSION_STRING VERSION_LESS "1.3.0")
message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.3.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}")
endif()

set(PICO_EXAMPLES_PATH ${PROJECT_SOURCE_DIR})

# Initialize the SDK
pico_sdk_init()

include(example_auto_set_url.cmake)
# Add blink example
# add_subdirectory(blink)

# Add hello world example
# add_subdirectory(hello_world)

add_compile_options(-Wall
-Wno-format # int != int32_t as far as the compiler is concerned because gcc has int32_t as long int
-Wno-unused-function # we have some for the docs that aren't called
-Wno-maybe-uninitialized
)

# Hardware-specific examples in subdirectories:
add_subdirectory(pio)
1 change: 1 addition & 0 deletions p4/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(build_variants)
37 changes: 37 additions & 0 deletions p4/cmake/build_variants/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 1 Create an INTERFACE library aggregating all the common parts of the application
add_library(common_stuff INTERFACE)

# note cmake policy is to use absolute paths for interface libraries.
target_sources(common_stuff INTERFACE
${CMAKE_CURRENT_LIST_DIR}/main.c
${CMAKE_CURRENT_LIST_DIR}/other.c
)

target_compile_definitions(common_stuff INTERFACE
A_DEFINE_THAT_IS_SHARED=123
)

# can include library dependencies here
target_link_libraries(common_stuff INTERFACE
pico_stdlib
)

# 2 Create the first executable including all the common stuff...
# we can set compile definitions for this executable here too. Because
# we depend on an INTERFACE library (common_stuff) we
# will pick up all of its definitions/dependencies too
add_executable(build_variant1)
target_link_libraries(build_variant1 common_stuff)
target_compile_definitions(build_variant1 PRIVATE
A_DEFINE_THAT_IS_NOT_SHARED=456)
pico_add_extra_outputs(build_variant1)

# 3 Create a second executable including all the common stuff
# this version also sets the DO_EXTRA define
add_executable(build_variant2)
target_link_libraries(build_variant2 common_stuff)
target_compile_definitions(build_variant2 PRIVATE
A_DEFINE_THAT_IS_NOT_SHARED=789
DO_EXTRA)
pico_add_extra_outputs(build_variant2)

18 changes: 18 additions & 0 deletions p4/cmake/build_variants/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <stdio.h>
#include "pico/stdlib.h"
#include "other.h"

int main() {
stdio_init_all();
do_other();
#ifdef DO_EXTRA
printf("A little extra\n");
#endif
return 0;
}
15 changes: 15 additions & 0 deletions p4/cmake/build_variants/other.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <stdio.h>
#include "other.h"

void do_other() {
printf("The common thing is %d\n",
A_DEFINE_THAT_IS_SHARED);
printf("The binary local thing is %d\n",
A_DEFINE_THAT_IS_NOT_SHARED);
}
7 changes: 7 additions & 0 deletions p4/cmake/build_variants/other.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

void do_other();
5 changes: 5 additions & 0 deletions p4/example_auto_set_url.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set(PICO_EXAMPLE_URL_BASE "https://github.com/raspberrypi/pico-examples/tree/HEAD")
macro(example_auto_set_url TARGET)
file(RELATIVE_PATH URL_REL_PATH "${PICO_EXAMPLES_PATH}" "${CMAKE_CURRENT_LIST_DIR}")
pico_set_program_url(${TARGET} "${PICO_EXAMPLE_URL_BASE}/${URL_REL_PATH}")
endmacro()
73 changes: 73 additions & 0 deletions p4/pico_sdk_import.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# This is a copy of <PICO_SDK_PATH>/external/pico_sdk_import.cmake

# This can be dropped into an external project to help locate this SDK
# It should be include()ed prior to project()

if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH))
set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")
endif ()

if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT))
set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT})
message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')")
endif ()

if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH))
set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH})
message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
endif ()

set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK")
set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable")
set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK")

if (NOT PICO_SDK_PATH)
if (PICO_SDK_FETCH_FROM_GIT)
include(FetchContent)
set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR})
if (PICO_SDK_FETCH_FROM_GIT_PATH)
get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
endif ()
# GIT_SUBMODULES_RECURSE was added in 3.17
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0")
FetchContent_Declare(
pico_sdk
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
GIT_TAG master
GIT_SUBMODULES_RECURSE FALSE
)
else ()
FetchContent_Declare(
pico_sdk
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
GIT_TAG master
)
endif ()

if (NOT pico_sdk)
message("Downloading Raspberry Pi Pico SDK")
FetchContent_Populate(pico_sdk)
set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
endif ()
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
else ()
message(FATAL_ERROR
"SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git."
)
endif ()
endif ()

get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
if (NOT EXISTS ${PICO_SDK_PATH})
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found")
endif ()

set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake)
if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE})
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK")
endif ()

set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE)

include(${PICO_SDK_INIT_CMAKE_FILE})
Loading